summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-07-21 15:28:50 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-07-21 15:28:50 +0000
commitb154ecafa62fa6cce2c3eedcfec2baa45f343580 (patch)
tree3dd9f5c52b5c79d0cbbe421cae4dbeb9d3c5ff26 /clang/lib/Sema/SemaDecl.cpp
parent82fe3e3398e9eb16ade4970bfb1dc15023c5e8be (diff)
downloadbcm5719-llvm-b154ecafa62fa6cce2c3eedcfec2baa45f343580.tar.gz
bcm5719-llvm-b154ecafa62fa6cce2c3eedcfec2baa45f343580.zip
Diagnose when a destructor uses a unrelated class type as its name.
llvm-svn: 76577
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 36cb656966f..989e08ee9da 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2456,6 +2456,16 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl,
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.
OpenPOWER on IntegriCloud