From: Douglas Gregor Date: Tue, 16 Feb 2010 19:28:15 +0000 (+0000) Subject: Do not try to instantiate invalid declarations. It's a recipe for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2fa98001f832836e3f652c211a9d2f80501d659a;p=clang Do not try to instantiate invalid declarations. It's a recipe for disaster. Fixes PR6161. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96371 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 0b0efcb833..f13bd69453 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1304,6 +1304,9 @@ Decl * TemplateDeclInstantiator Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs) { TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs); + if (D->isInvalidDecl()) + return 0; + return Instantiator.Visit(D); } diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index acd4a23cb3..68323d8d07 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -159,12 +159,10 @@ void loadEngineFor() { } template struct TBase { - void* operator new(T size, int); // expected-error {{'operator new' cannot take a dependent type as first parameter; use size_t}}\ - // expected-error {{'operator new' takes type size_t}} + void* operator new(T size, int); // expected-error {{'operator new' cannot take a dependent type as first parameter; use size_t}} }; -// FIXME: We should not try to instantiate operator new, since it is invalid. -TBase t1; // expected-note {{in instantiation of template class 'struct TBase' requested here}} +TBase t1; class X6 { public: diff --git a/test/SemaTemplate/explicit-specialization-member.cpp b/test/SemaTemplate/explicit-specialization-member.cpp index 06dd382fc7..417cdc1f19 100644 --- a/test/SemaTemplate/explicit-specialization-member.cpp +++ b/test/SemaTemplate/explicit-specialization-member.cpp @@ -9,3 +9,15 @@ struct X0 { template<> void X0::f0(char); template<> void X0::f1(type); + +namespace PR6161 { + template + class numpunct : public locale::facet // expected-error{{use of undeclared identifier 'locale'}} \ + // expected-error{{expected class name}} \ + // expected-note{{attempt to specialize declaration here}} + { + static locale::id id; // expected-error{{use of undeclared identifier}} + }; + numpunct::~numpunct(); // expected-error{{template specialization requires 'template<>'}} \ + // expected-error{{specialization of member 'PR6161::numpunct::~numpunct' does not specialize an instantiated member}} +}