]> granicus.if.org Git - clang/commitdiff
Diagnose destructor templates. Fixes PR7904.
authorDouglas Gregor <dgregor@apple.com>
Fri, 4 Mar 2011 22:45:55 +0000 (22:45 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 4 Mar 2011 22:45:55 +0000 (22:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127042 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaCXX/friend.cpp
test/SemaTemplate/destructor-template.cpp

index 38e072e8de4a7340c411888c9736253f292a42f3..f661bdb2743b28ff87e3346f663074f397d98088 100644 (file)
@@ -799,6 +799,9 @@ def err_destructor_expr_type_mismatch : Error<
 def note_destructor_type_here : Note<
   "type %0 is declared here">;
 
+def err_destructor_template : Error<
+  "destructor cannot be declared as a template">;
+
 // C++ initialization
 def err_init_conversion_failed : Error<
   "cannot initialize %select{a variable|a parameter|return object|an "
index 10d92029f85e37618177f3f84ea6197f98322e05..e6c459504e2a39871879407fd5d2dd2c77a0df42 100644 (file)
@@ -3755,7 +3755,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
     // determine whether we have a template or a template specialization.
     bool Invalid = false;
     if (TemplateParameterList *TemplateParams
-        = MatchTemplateParametersToScopeSpecifier(
+          = MatchTemplateParametersToScopeSpecifier(
                                   D.getDeclSpec().getSourceRange().getBegin(),
                                   D.getCXXScopeSpec(),
                                   TemplateParamLists.get(),
@@ -3773,6 +3773,13 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
             if (CheckTemplateDeclScope(S, TemplateParams))
               return 0;
 
+            // A destructor cannot be a template.
+            if (Name.getNameKind() == DeclarationName::CXXDestructorName) {
+              Diag(NewFD->getLocation(), diag::err_destructor_template);
+              return 0;
+            }
+            
+            
             FunctionTemplate = FunctionTemplateDecl::Create(Context, DC,
                                                       NewFD->getLocation(),
                                                       Name, TemplateParams,
index 1222dd0940da0f45f13a4827fc629b92b7f35e41..b1ef220e534c823c5a2eef680ea3ef7381a75abc 100644 (file)
@@ -64,11 +64,11 @@ namespace test4 {
 }
 
 namespace rdar8529993 {
-struct A { ~A(); }; // expected-note {{nearly matches}}
+struct A { ~A(); };
 
 struct B : A
 {
-  template<int> friend A::~A(); // expected-error {{does not match}}
+  template<int> friend A::~A(); // expected-error {{destructor cannot be declared as a template}}
 };
 }
 
index 6fe7f69cdd5fda61220dab1b18e7a0f2fb9047d2..07beda40aaa7484566afbdf1629f05c09154e473 100644 (file)
@@ -50,3 +50,10 @@ namespace PR7239 {
     }
   };
 }
+
+namespace PR7904 {
+  struct Foo {
+    template <int i> ~Foo() {} // expected-error{{destructor cannot be declared as a template}}
+  };
+  Foo f;
+}