]> granicus.if.org Git - clang/commitdiff
In Parser::ParseDecltypeSpecifier, make sure the end location it returns
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 26 Oct 2012 22:53:44 +0000 (22:53 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 26 Oct 2012 22:53:44 +0000 (22:53 +0000)
is at the end of parsed tokens when an error occurs, otherwise we'll hit
an assertion when trying to annotate the decltype tokens.

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

lib/Parse/ParseDeclCXX.cpp
test/SemaCXX/decltype.cpp

index e656a6bd7660885547118a8ed85b9315ccf1be65..492250da1d49ac7df8337e5487489963de41cd6d 100644 (file)
@@ -696,9 +696,22 @@ SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec &DS) {
                                                  0, /*IsDecltype=*/true);
     Result = ParseExpression();
     if (Result.isInvalid()) {
-      SkipUntil(tok::r_paren);
       DS.SetTypeSpecError();
-      return StartLoc;
+      if (SkipUntil(tok::r_paren, /*StopAtSemi=*/true, /*DontConsume=*/true)) {
+        EndLoc = ConsumeParen();
+      } else {
+        assert(Tok.is(tok::semi));
+        if (PP.isBacktrackEnabled()) {
+          // Backtrack to get the location of the last token before the semi.
+          PP.RevertCachedTokens(2);
+          ConsumeToken(); // the semi.
+          EndLoc = ConsumeAnyToken();
+          assert(Tok.is(tok::semi));
+        } else {
+          EndLoc = Tok.getLocation();
+        }
+      }
+      return EndLoc;
     }
 
     // Match the ')'
index ef3103ded7a982a545005ad811c9d45a76a0d6aa..f9bdececc4f65011add2f9e951b7e377da969106 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 // PR5290
 int const f0();
@@ -29,3 +28,11 @@ template<typename T> auto f(T t) -> decltype(S<int>(t)) {
   using U = S<int>;
   return S<int>(t);
 }
+
+struct B {
+  B(decltype(undeclared)); // expected-error {{undeclared identifier}}
+};
+struct C {
+  C(decltype(undeclared; // expected-error {{undeclared identifier}} \
+                         // expected-error {{expected ')'}} expected-note {{to match this '('}}
+};