]> granicus.if.org Git - clang/commitdiff
DR1511: A const volatile global does not implicitly get internal linkage like a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 19 Oct 2012 06:37:48 +0000 (06:37 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 19 Oct 2012 06:37:48 +0000 (06:37 +0000)
const non-volatile global does.

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

lib/AST/Decl.cpp
test/CodeGenCXX/const-global-linkage.cpp

index 442deca11be0c72a8de77307cc7d5afbfbf7483f..8e4ba0c5d2f260d4dadf925b03a1e7eac725f46a 100644 (file)
@@ -213,12 +213,12 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D,
     if (Var->getStorageClass() == SC_Static)
       return LinkageInfo::internal();
 
-    // - an object or reference that is explicitly declared const
-    //   and neither explicitly declared extern nor previously
-    //   declared to have external linkage; or
-    // (there is no equivalent in C99)
+    // - a non-volatile object or reference that is explicitly declared const
+    //   or constexpr and neither explicitly declared extern nor previously
+    //   declared to have external linkage; or (there is no equivalent in C99)
     if (Context.getLangOpts().CPlusPlus &&
-        Var->getType().isConstant(Context) && 
+        Var->getType().isConstQualified() && 
+        !Var->getType().isVolatileQualified() &&
         Var->getStorageClass() != SC_Extern &&
         Var->getStorageClass() != SC_PrivateExtern) {
       bool FoundExtern = false;
index d0a055b494959e1c4335b9106dc0b320804a36ad..df78fdd0287ccb91056e7a4df83f2bba447b0bb6 100644 (file)
@@ -2,12 +2,16 @@
 
 const int x = 10;
 const int y = 20;
+const volatile int z = 30;
 // CHECK-NOT: @x
+// CHECK: @z = constant i32 30
 // CHECK: @_ZL1y = internal constant i32 20
 const int& b() { return y; }
 
 const char z1[] = "asdf";
 const char z2[] = "zxcv";
+const volatile char z3[] = "zxcv";
 // CHECK-NOT: @z1
+// CHECK: @z3 = constant
 // CHECK: @_ZL2z2 = internal constant
 const char* b2() { return z2; }