aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-12-05 11:34:06 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-12-05 11:34:06 +0000
commit37ec8d589c5de34d0e260f0599395519bd7498de (patch)
treeb92d24be4aba6baf967b2adbe697eaaccbaccb8e
parent5b10af7aa9e254a38d0a9f4d86caaccd61972124 (diff)
In C++, if we hit an error in the class-head, don't try to parse the class body.
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
-rw-r--r--lib/Sema/SemaDecl.cpp4
-rw-r--r--test/Parser/cxx-undeclared-identifier.cpp2
-rw-r--r--test/Parser/recovery.cpp7
3 files changed, 10 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 341e8feba6..102a6ae9a2 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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) {
diff --git a/test/Parser/cxx-undeclared-identifier.cpp b/test/Parser/cxx-undeclared-identifier.cpp
index 6ea2965913..a3f9e02794 100644
--- a/test/Parser/cxx-undeclared-identifier.cpp
+++ b/test/Parser/cxx-undeclared-identifier.cpp
@@ -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 '}'}}
diff --git a/test/Parser/recovery.cpp b/test/Parser/recovery.cpp
index 732b9aee16..41845fb291 100644
--- a/test/Parser/recovery.cpp
+++ b/test/Parser/recovery.cpp
@@ -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() {}
+};