]> granicus.if.org Git - clang/commitdiff
Fix some C++ error recovery problems in init declarator parsing
authorChris Lattner <sabre@nondot.org>
Sun, 12 Apr 2009 22:23:27 +0000 (22:23 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 12 Apr 2009 22:23:27 +0000 (22:23 +0000)
that I noticed working on other things.

Instead of emitting:

t2.cc:1:8: error: use of undeclared identifier 'g'
int x(*g);
       ^
t2.cc:1:10: error: expected ')'
int x(*g);
         ^
t2.cc:1:6: note: to match this '('
int x(*g);
     ^

We now only emit:

t2.cc:1:7: warning: type specifier missing, defaults to 'int'
int x(*g);
      ^

Note that the example in SemaCXX/nested-name-spec.cpp:f4 is still
not great, we now produce both of:

void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \
                      expected-error {{variable has incomplete type 'void'}}

The second diagnostic should be silenced by something getting marked invalid.
I don't plan to fix this though.

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

lib/Parse/ParseDecl.cpp
test/Parser/cxx-decl.cpp [new file with mode: 0644]
test/SemaCXX/nested-name-spec.cpp

index 5b8963f892c2b16e24750c385ec7d6d7d2d0c548..da3ee1df7c5443d0c762c497fd81e2351fcf2d71 100644 (file)
@@ -380,15 +380,12 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
       ExprVector Exprs(Actions);
       CommaLocsTy CommaLocs;
 
-      bool InvalidExpr = false;
       if (ParseExpressionList(Exprs, CommaLocs)) {
         SkipUntil(tok::r_paren);
-        InvalidExpr = true;
-      }
-      // Match the ')'.
-      SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
+      } else {
+        // Match the ')'.
+        SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
 
-      if (!InvalidExpr) {
         assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
                "Unexpected number of commas!");
         Actions.AddCXXDirectInitializerToDecl(ThisDecl, LParenLoc,
diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp
new file mode 100644 (file)
index 0000000..3fa2842
--- /dev/null
@@ -0,0 +1,3 @@
+// RUN: clang-cc -verify -fsyntax-only %s
+
+int x(*g); // expected-error {{use of undeclared identifier 'g'}}
index fe92aab9a263e1e5de261ee75bd619b2537a9def..29fa001e0fff11dfec7862365904a30ec282104e 100644 (file)
@@ -93,7 +93,8 @@ void f3() {
 }
 
 // make sure the following doesn't hit any asserts
-void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} // expected-error {{expected ')'}} expected-note {{to match this '('}} // expected-error {{variable has incomplete type 'void'}}
+void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \
+                      expected-error {{variable has incomplete type 'void'}}
 
 typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}