[cfe-commits] r127042 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/friend.cpp test/SemaTemplate/destructor-template.cpp
Douglas Gregor
dgregor at apple.com
Fri Mar 4 14:45:55 PST 2011
Author: dgregor
Date: Fri Mar 4 16:45:55 2011
New Revision: 127042
URL: http://llvm.org/viewvc/llvm-project?rev=127042&view=rev
Log:
Diagnose destructor templates. Fixes PR7904.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/friend.cpp
cfe/trunk/test/SemaTemplate/destructor-template.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127042&r1=127041&r2=127042&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Mar 4 16:45:55 2011
@@ -799,6 +799,9 @@
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 "
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127042&r1=127041&r2=127042&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar 4 16:45:55 2011
@@ -3755,7 +3755,7 @@
// 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 @@
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,
Modified: cfe/trunk/test/SemaCXX/friend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/friend.cpp?rev=127042&r1=127041&r2=127042&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/friend.cpp (original)
+++ cfe/trunk/test/SemaCXX/friend.cpp Fri Mar 4 16:45:55 2011
@@ -64,11 +64,11 @@
}
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}}
};
}
Modified: cfe/trunk/test/SemaTemplate/destructor-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/destructor-template.cpp?rev=127042&r1=127041&r2=127042&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/destructor-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/destructor-template.cpp Fri Mar 4 16:45:55 2011
@@ -50,3 +50,10 @@
}
};
}
+
+namespace PR7904 {
+ struct Foo {
+ template <int i> ~Foo() {} // expected-error{{destructor cannot be declared as a template}}
+ };
+ Foo f;
+}
More information about the cfe-commits
mailing list