From: Douglas Gregor Date: Mon, 27 Jul 2009 17:43:39 +0000 (+0000) Subject: When instantiating a variable without an initializer, call X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65b90055dd30cfb83d8344ff62ed428257431be4;p=clang When instantiating a variable without an initializer, call ActOnUninitializedDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77211 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index a6513f1672..b04b63523d 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -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. diff --git a/test/SemaTemplate/instantiate-static-var.cpp b/test/SemaTemplate/instantiate-static-var.cpp index 99e6b9cc06..ebf6658ba3 100644 --- a/test/SemaTemplate/instantiate-static-var.cpp +++ b/test/SemaTemplate/instantiate-static-var.cpp @@ -16,3 +16,25 @@ class Y { }; Y fy; // expected-note{{in instantiation of template class 'class Y' requested here}} + + +// out-of-line static member variables + +template +struct Z { + static T value; +}; + +template +T Z::value; // expected-error{{no matching constructor}} + +struct DefCon {}; + +struct NoDefCon { + NoDefCon(const NoDefCon&); +}; + +void test() { + DefCon &DC = Z::value; + NoDefCon &NDC = Z::value; // expected-note{{instantiation}} +} \ No newline at end of file