]> granicus.if.org Git - clang/commitdiff
Do not try to instantiate invalid declarations. It's a recipe for
authorDouglas Gregor <dgregor@apple.com>
Tue, 16 Feb 2010 19:28:15 +0000 (19:28 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 16 Feb 2010 19:28:15 +0000 (19:28 +0000)
disaster. Fixes PR6161.

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

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaCXX/new-delete.cpp
test/SemaTemplate/explicit-specialization-member.cpp

index 0b0efcb8332750857141fcc22b54d9d8aa4dd18f..f13bd69453d672976da4b8a4b8721ff13dcb7aa7 100644 (file)
@@ -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);
 }
 
index acd4a23cb35afd6a7c6fcf20c0db3fd2df55830b..68323d8d0756a90ce1cd8c98b97fc5b296c03800 100644 (file)
@@ -159,12 +159,10 @@ void loadEngineFor() {
 }
 
 template <class T> 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<int> t1; // expected-note {{in instantiation of template class 'struct TBase<int>' requested here}}
+TBase<int> t1;
 
 class X6 {
 public:
index 06dd382fc7a4d8c437872e1ba23aecff03900d5c..417cdc1f1987b6a7ab3ad171e6092281bc61dcdb 100644 (file)
@@ -9,3 +9,15 @@ struct X0 {
 
 template<> void X0<char>::f0(char);
 template<> void X0<char>::f1(type);
+
+namespace PR6161 {
+  template<typename _CharT>
+  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<char>::~numpunct(); // expected-error{{template specialization requires 'template<>'}} \
+  // expected-error{{specialization of member 'PR6161::numpunct<char>::~numpunct' does not specialize an instantiated member}}
+}