aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/CodeGen/CodeGenModule.cpp16
-rw-r--r--test/CodeGenCXX/static-member-variable-explicit-specialization.cpp11
2 files changed, 22 insertions, 5 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 4b3b122b71..5656b4657a 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -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
index 0000000000..d439cbd500
--- /dev/null
+++ b/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
@@ -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;
+
+