]> granicus.if.org Git - clang/commitdiff
In C++, if we hit an error in the class-head, don't try to parse the class body.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 5 Dec 2012 11:34:06 +0000 (11:34 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 5 Dec 2012 11:34:06 +0000 (11:34 +0000)
Our error recovery path may have made the class anonymous, and that has a pretty
disastrous impact on any attempt to parse a class body containing constructors.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169374 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Parser/cxx-undeclared-identifier.cpp
test/Parser/recovery.cpp

index 341e8feba617c56e3faf556ca5888be063f9ca43..102a6ae9a237748fa6c47c98fb173272f2c68912 100644 (file)
@@ -9299,7 +9299,9 @@ CreateNewDecl:
   AddPushedVisibilityAttribute(New);
 
   OwnedDecl = true;
-  return New;
+  // In C++, don't return an invalid declaration. We can't recover well from
+  // the cases where we make the type anonymous.
+  return (Invalid && getLangOpts().CPlusPlus) ? 0 : New;
 }
 
 void Sema::ActOnTagStartDefinition(Scope *S, Decl *TagD) {
index 6ea2965913a97763ba4b6996031c2959d72288b1..a3f9e0279496d01dd2db6ec40c86bf088ddc624a 100644 (file)
@@ -16,6 +16,4 @@ namespace ImplicitInt {
 int f(a::b::c); // expected-error {{use of undeclared identifier 'a'}}
 
 class Foo::Bar { // expected-error {{use of undeclared identifier 'Foo'}} \
-                 // expected-note {{to match this '{'}} \
                  // expected-error {{expected ';' after class}}
-                 // expected-error {{expected '}'}}
index 732b9aee1632c5dedb3a81b5ed27b1649535f3dc..41845fb291584c5e1dfcfc286e19d98ebe388278 100644 (file)
@@ -43,3 +43,10 @@ strcut Uuuu { // expected-error {{did you mean the keyword 'struct'}} \
               // expected-note {{'Uuuu' declared here}}
 } *u[3];
 uuuu v; // expected-error {{did you mean 'Uuuu'}}
+
+struct Redefined { // expected-note {{previous}}
+  Redefined() {}
+};
+struct Redefined { // expected-error {{redefinition}}
+  Redefined() {}
+};