]> granicus.if.org Git - clang/commitdiff
When instantiating a variable without an initializer, call
authorDouglas Gregor <dgregor@apple.com>
Mon, 27 Jul 2009 17:43:39 +0000 (17:43 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 27 Jul 2009 17:43:39 +0000 (17:43 +0000)
ActOnUninitializedDecl.

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

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-static-var.cpp

index a6513f167263e73711c8e76fd7d1389153a74394..b04b63523df041d620b91cc62a884c04f2f094dc 100644 (file)
@@ -146,9 +146,8 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
     else
       SemaRef.AddInitializerToDecl(Sema::DeclPtrTy::make(Var), move(Init),
                                    D->hasCXXDirectInitializer());
-  } else {
-    // FIXME: Call ActOnUninitializedDecl? (Not always)
-  }
+  } else if (!Var->isStaticDataMember() || Var->isOutOfLine())
+    SemaRef.ActOnUninitializedDecl(Sema::DeclPtrTy::make(Var), false);
 
   // Link instantiations of static data members back to the template from
   // which they were instantiated.
index 99e6b9cc06c375d962586721b18d9733e375e7ad..ebf6658ba3a3bdde394bb3804ba5436d45a49b78 100644 (file)
@@ -16,3 +16,25 @@ class Y {
 };
 
 Y<float> fy; // expected-note{{in instantiation of template class 'class Y<float>' requested here}}
+
+
+// out-of-line static member variables
+
+template<typename T>
+struct Z {
+  static T value;
+};
+
+template<typename T>
+T Z<T>::value; // expected-error{{no matching constructor}}
+
+struct DefCon {};
+
+struct NoDefCon { 
+  NoDefCon(const NoDefCon&);
+};
+
+void test() {
+  DefCon &DC = Z<DefCon>::value;
+  NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}}
+}
\ No newline at end of file