]> granicus.if.org Git - clang/commitdiff
For "expected unqualified-id" errors after a double colon, and the double colon
authorRichard Trieu <rtrieu@google.com>
Thu, 5 Sep 2013 02:31:33 +0000 (02:31 +0000)
committerRichard Trieu <rtrieu@google.com>
Thu, 5 Sep 2013 02:31:33 +0000 (02:31 +0000)
is at the end of the line, point to the location after the double colon instead
of at the next token.  There is more context to be given this way.  In addition,
the next token can be several lines later.

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

lib/Parse/ParseDecl.cpp
test/Parser/cxx-decl.cpp

index 5d47d3d9b80f4a18df00b63f5672558da3b938b8..48a30a15b1bc40511e11f5f302d303a502b4e1c3 100644 (file)
@@ -4779,8 +4779,15 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
     else if (getLangOpts().CPlusPlus) {
       if (Tok.is(tok::period) || Tok.is(tok::arrow))
         Diag(Tok, diag::err_invalid_operator_on_type) << Tok.is(tok::arrow);
-      else
-        Diag(Tok, diag::err_expected_unqualified_id) << getLangOpts().CPlusPlus;
+      else {
+        SourceLocation Loc = D.getCXXScopeSpec().getEndLoc();
+        if (Tok.isAtStartOfLine() && Loc.isValid())
+          Diag(PP.getLocForEndOfToken(Loc), diag::err_expected_unqualified_id)
+              << getLangOpts().CPlusPlus;
+        else
+          Diag(Tok, diag::err_expected_unqualified_id)
+              << getLangOpts().CPlusPlus;
+      }
     } else
       Diag(Tok, diag::err_expected_ident_lparen);
     D.SetIdentifier(0, Tok.getLocation());
index e3f3957d564cfa51bd3c63eeafa1b0620af87c2e..281e33b20f8b1d19e7686c6560ff6a026382dfe2 100644 (file)
@@ -187,6 +187,21 @@ namespace PR15017 {
 // Ensure we produce at least some diagnostic for attributes in C++98.
 [[]] struct S; // expected-error 2{{}}
 
+namespace test7 {
+  struct Foo {
+    void a();
+    void b();
+  };
+
+  void Foo::
+  // Comment!
+  a() {}
+
+
+  void Foo::  // expected-error {{expected unqualified-id}}
+  // Comment!
+}
+
 namespace PR5066 {
   template<typename T> struct X {};
   X<int N> x; // expected-error {{type-id cannot have a name}}