r197848 - Don't mark record decls invalid when one of its methods is invalid, PR18284.

Nico Weber nicolasweber at gmx.de
Fri Dec 20 16:49:51 PST 2013


Author: nico
Date: Fri Dec 20 18:49:51 2013
New Revision: 197848

URL: http://llvm.org/viewvc/llvm-project?rev=197848&view=rev
Log:
Don't mark record decls invalid when one of its methods is invalid, PR18284.

Without this patch, record decls with invalid out-of-line method delcs would
sometimes be marked invalid, but not always.  With this patch, they are
consistently never marked invalid.

(The code to do this was added in
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20100809/033154.html
, but the test from that revision is still passing.)

As far as I can tell, this was the only place where a class was marked invalid
after its definition was complete.


Added:
    cfe/trunk/test/SemaCXX/pr18284-crash-on-invalid.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/constructor-initializer.cpp
    cfe/trunk/test/SemaCXX/pr13394-crash-on-invalid.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=197848&r1=197847&r2=197848&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Dec 20 18:49:51 2013
@@ -7176,12 +7176,7 @@ Sema::ActOnFunctionDeclarator(Scope *S,
       if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint())
         CheckMSVCRTEntryPoint(NewFD);
 
-      if (NewFD->isInvalidDecl()) {
-        // If this is a class member, mark the class invalid immediately.
-        // This avoids some consistency errors later.
-        if (CXXMethodDecl* methodDecl = dyn_cast<CXXMethodDecl>(NewFD))
-          methodDecl->getParent()->setInvalidDecl();
-      } else
+      if (!NewFD->isInvalidDecl())
         D.setRedeclaration(CheckFunctionDeclaration(S, NewFD, Previous,
                                                     isExplicitSpecialization));
     }

Modified: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor-initializer.cpp?rev=197848&r1=197847&r2=197848&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp Fri Dec 20 18:49:51 2013
@@ -232,15 +232,14 @@ namespace PR7402 {
 // <rdar://problem/8308215>: don't crash.
 // Lots of questionable recovery here;  errors can change.
 namespace test3 {
-  class A : public std::exception {}; // expected-error {{undeclared identifier}} expected-error {{expected class name}} expected-note 4 {{candidate}}
+  class A : public std::exception {}; // expected-error {{undeclared identifier}} expected-error {{expected class name}} expected-note 2 {{candidate}}
   class B : public A {
   public:
     B(const String& s, int e=0) // expected-error {{unknown type name}} 
       : A(e), m_String(s) , m_ErrorStr(__null) {} // expected-error {{no matching constructor}} expected-error {{does not name}}
     B(const B& e)
       : A(e), m_String(e.m_String), m_ErrorStr(__null) { // expected-error {{does not name}} \
-      // expected-error {{no member named 'm_String' in 'test3::B'}} \
-      // expected-error {{no matching}}
+      // expected-error {{no member named 'm_String' in 'test3::B'}}
     }
   };
 }

Modified: cfe/trunk/test/SemaCXX/pr13394-crash-on-invalid.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pr13394-crash-on-invalid.cpp?rev=197848&r1=197847&r2=197848&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/pr13394-crash-on-invalid.cpp (original)
+++ cfe/trunk/test/SemaCXX/pr13394-crash-on-invalid.cpp Fri Dec 20 18:49:51 2013
@@ -8,12 +8,12 @@ namespace stretch_v1 {
 }
 namespace gatekeeper_v1 {
   namespace gatekeeper_factory_v1 {
-    struct closure_t { // expected-note {{'closure_t' declared here}}
+    struct closure_t { // expected-note {{'closure_t' declared here}} expected-note {{'gatekeeper_factory_v1::closure_t' declared here}}
       gatekeeper_v1::closure_t* create(); // expected-error {{no type named 'closure_t' in namespace 'gatekeeper_v1'; did you mean simply 'closure_t'?}}
     };
   }
   // FIXME: Typo correction should remove the 'gatekeeper_v1::' name specifier
-  gatekeeper_v1::closure_t *x; // expected-error-re {{no type named 'closure_t' in namespace 'gatekeeper_v1'{{$}}}}
+  gatekeeper_v1::closure_t *x; // expected-error {{no type named 'closure_t' in namespace 'gatekeeper_v1'; did you mean 'gatekeeper_factory_v1::closure_t'}}
 }
 
 namespace Foo {

Added: cfe/trunk/test/SemaCXX/pr18284-crash-on-invalid.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pr18284-crash-on-invalid.cpp?rev=197848&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/pr18284-crash-on-invalid.cpp (added)
+++ cfe/trunk/test/SemaCXX/pr18284-crash-on-invalid.cpp Fri Dec 20 18:49:51 2013
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// Don't crash (PR18284).
+
+namespace n1 {
+class A { };
+class C { A a; };
+
+A::RunTest() {} // expected-error {{C++ requires a type specifier for all declarations}}
+
+void f() {
+  new C;
+}
+} // namespace n1
+
+namespace n2 {
+class A { };
+class C : public A { };
+
+A::RunTest() {} // expected-error {{C++ requires a type specifier for all declarations}}
+
+void f() {
+  new C;
+}
+} // namespace n2





More information about the cfe-commits mailing list