[cfe-commits] r76577 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/destructor.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Jul 21 08:29:01 PDT 2009
Author: fjahanian
Date: Tue Jul 21 10:28:50 2009
New Revision: 76577
URL: http://llvm.org/viewvc/llvm-project?rev=76577&view=rev
Log:
Diagnose when a destructor uses a unrelated class type as its name.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/destructor.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=76577&r1=76576&r2=76577&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul 21 10:28:50 2009
@@ -385,6 +385,8 @@
def err_destructor_variadic : Error<"destructor cannot be variadic">;
def err_destructor_typedef_name : Error<
"destructor cannot be declared using a typedef %0 of the class name">;
+def err_destructor_name : Error<
+ "expected the class name after '~' to name the enclosing class">;
// C++ initialization
def err_lvalue_to_rvalue_ref : Error<"rvalue reference cannot bind to lvalue">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=76577&r1=76576&r2=76577&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jul 21 10:28:50 2009
@@ -2456,6 +2456,16 @@
CheckConstructor(Constructor);
} else if (isa<CXXDestructorDecl>(NewFD)) {
CXXRecordDecl *Record = cast<CXXRecordDecl>(NewFD->getParent());
+ QualType ClassType = Context.getTypeDeclType(Record);
+ if (!ClassType->isDependentType()) {
+ ClassType = Context.getCanonicalType(ClassType);
+ DeclarationName Name
+ = Context.DeclarationNames.getCXXDestructorName(ClassType);
+ if (NewFD->getDeclName() != Name) {
+ Diag(NewFD->getLocation(), diag::err_destructor_name);
+ return NewFD->setInvalidDecl();
+ }
+ }
Record->setUserDeclaredDestructor(true);
// C++ [class]p4: A POD-struct is an aggregate class that has [...] no
// user-defined destructor.
Modified: cfe/trunk/test/SemaCXX/destructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/destructor.cpp?rev=76577&r1=76576&r2=76577&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/destructor.cpp (original)
+++ cfe/trunk/test/SemaCXX/destructor.cpp Tue Jul 21 10:28:50 2009
@@ -55,3 +55,9 @@
struct H {
~H(void) { }
};
+
+struct X {};
+
+struct Y {
+ ~X(); // expected-error {{expected the class name after '~' to name the enclosing class}}
+};
More information about the cfe-commits
mailing list