]> granicus.if.org Git - clang/commitdiff
Don't emit explicit specializations of static member variable declarations.
authorAnders Carlsson <andersca@mac.com>
Fri, 4 Dec 2009 23:50:01 +0000 (23:50 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 4 Dec 2009 23:50:01 +0000 (23:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90624 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/static-member-variable-explicit-specialization.cpp [new file with mode: 0644]

index 4b3b122b71cfbe8d239183830bb28eb8e4f4a94c..5656b4657a4a013106b75c539b345b52dfc1b3e2 100644 (file)
@@ -576,11 +576,17 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
     const VarDecl *VD = cast<VarDecl>(Global);
     assert(VD->isFileVarDecl() && "Cannot emit local var decl as global.");
 
-    // In C++, if this is marked "extern", defer code generation.
-    if (getLangOptions().CPlusPlus && !VD->getInit() &&
-        (VD->getStorageClass() == VarDecl::Extern ||
-         VD->isExternC()))
-      return;
+    if (getLangOptions().CPlusPlus && !VD->getInit()) {
+      // In C++, if this is marked "extern", defer code generation.
+      if (VD->getStorageClass() == VarDecl::Extern || VD->isExternC())
+        return;
+
+      // If this is a declaration of an explicit specialization of a static
+      // data member in a class template, don't emit it.
+      if (VD->isStaticDataMember() && 
+          VD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+        return;
+    }
 
     // In C, if this isn't a definition, defer code generation.
     if (!getLangOptions().CPlusPlus && !VD->getInit())
diff --git a/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp b/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
new file mode 100644 (file)
index 0000000..d439cbd
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: clang-cc %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// CHECK: ; ModuleID
+template<typename> struct A { static int a; };
+
+// CHECK-NOT: @_ZN1AIcE1aE
+template<> int A<char>::a;
+
+// CHECK: @_ZN1AIbE1aE = global i32 10
+template<> int A<bool>::a = 10;
+
+