]> granicus.if.org Git - clang/commitdiff
It is not error in c++ to take address of
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 24 Aug 2010 22:21:48 +0000 (22:21 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 24 Aug 2010 22:21:48 +0000 (22:21 +0000)
register variable (c++03 7.1.1P3). radar 8108252.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111977 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/address-of-register-var.cpp [new file with mode: 0644]

index bd76b9ff129f5527e029a76b0b22407ac156d568..6acef58f2c2cdfd49ba5d6ebdec7e0e63a453035 100644 (file)
@@ -6278,7 +6278,10 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) {
     // We have an lvalue with a decl. Make sure the decl is not declared
     // with the register storage-class specifier.
     if (const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
-      if (vd->getStorageClass() == VarDecl::Register) {
+      // in C++ it is not error to take address of a register
+      // variable (c++03 7.1.1P3)
+      if (vd->getStorageClass() == VarDecl::Register &&
+          !getLangOptions().CPlusPlus) {
         Diag(OpLoc, diag::err_typecheck_address_of)
           << "register variable" << op->getSourceRange();
         return QualType();
diff --git a/test/SemaCXX/address-of-register-var.cpp b/test/SemaCXX/address-of-register-var.cpp
new file mode 100644 (file)
index 0000000..5d391c5
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar // 8018252
+
+void f0() {
+  extern void f0_1(int*);
+  register int x;
+  f0_1(&x);
+}
+