From 12d53da8cb4bbe43bb92c38a770f2cd5b3679cd0 Mon Sep 17 00:00:00 2001 From: John McCall Date: Thu, 12 Aug 2010 00:57:17 +0000 Subject: Fix a crash on invalid when declaring an implicit member of a class with an invalid destructor. llvm-svn: 110891 --- clang/lib/Sema/SemaDecl.cpp | 8 +++++++- clang/test/SemaCXX/destructor.cpp | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'clang') diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index de7ad3d791d..b27f727b3c5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3652,8 +3652,14 @@ void Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, bool &Redeclaration, bool &OverloadableAttrRequired) { // If NewFD is already known erroneous, don't do any of this checking. - if (NewFD->isInvalidDecl()) + if (NewFD->isInvalidDecl()) { + // If this is a class member, mark the class invalid immediately. + // This avoids some consistency errors later. + if (isa(NewFD)) + cast(NewFD)->getParent()->setInvalidDecl(); + return; + } if (NewFD->getResultType()->isVariablyModifiedType()) { // Functions returning a variably modified type violate C99 6.7.5.2p2 diff --git a/clang/test/SemaCXX/destructor.cpp b/clang/test/SemaCXX/destructor.cpp index 1502f734712..cdcae2e4119 100644 --- a/clang/test/SemaCXX/destructor.cpp +++ b/clang/test/SemaCXX/destructor.cpp @@ -105,3 +105,17 @@ namespace test6 { class B : A { B(); }; B::B() {} // expected-note {{in instantiation of member function 'test6::A::~A' requested here}} } + +// Make sure classes are marked invalid when they have invalid +// members. This avoids a crash-on-invalid. +namespace test7 { + struct A { + ~A() const; // expected-error {{'const' qualifier is not allowed on a destructor}} + }; + struct B : A {}; + + void test() { + B *b; + b->~B(); + } +} -- cgit v1.2.3