[PATCH] Add context to "expected unqualified-id" message

Eli Friedman eli.friedman at gmail.com
Mon Jun 24 17:13:10 PDT 2013


On Mon, Jun 24, 2013 at 4:58 PM, Richard Trieu <rtrieu at google.com> wrote:

> When the error message "expected unqualified-id" appears in the middle of
> parsing a declarator, and the token pointed to begins a new line, add a
> note that points back to the rest of the declarator.  This is to prevent
> the confusing case where an "expected unqualified-id" message shows up and
> points to a line of code where there is a single '}'.
>
> http://llvm-reviews.chandlerc.com/D1032
>
> Files:
>   lib/Parse/ParseDecl.cpp
>   test/Parser/cxx-decl.cpp
>   include/clang/Basic/DiagnosticParseKinds.td
>
> Index: lib/Parse/ParseDecl.cpp
> ===================================================================
> --- lib/Parse/ParseDecl.cpp
> +++ lib/Parse/ParseDecl.cpp
> @@ -4737,8 +4737,14 @@
>      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
> +      else {
>          Diag(Tok, diag::err_expected_unqualified_id) <<
> getLangOpts().CPlusPlus;
> +        if (Tok.isAtStartOfLine()) {
> +          SourceLocation Loc = D.getCXXScopeSpec().getEndLoc();
> +          if (Loc.isValid())
> +            Diag(PP.getLocForEndOfToken(Loc), diag::note_after_here);
> +        }
> +      }
>      } else
>        Diag(Tok, diag::err_expected_ident_lparen);
>      D.SetIdentifier(0, Tok.getLocation());
> Index: test/Parser/cxx-decl.cpp
> ===================================================================
> --- test/Parser/cxx-decl.cpp
> +++ test/Parser/cxx-decl.cpp
> @@ -187,6 +187,22 @@
>  // Ensure we produce at least some diagnostic for attributes in C++98.
>  [[]] struct S; // expected-error 2{{}}
>
> +namespace test7 {
> +  struct Foo {
> +    int a();
> +    int b();
> +  };
> +
> +  int Foo::
> +  // Comment!
> +  a() {}
> +
> +
> +  int Foo::
> +  // expected-note at -1 {{after here}}
> +  // Comment!
> +} // expected-error {{expected unqualified-id}}
>
>
Why don't we just point the error at the first location?

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130624/a61a8398/attachment.html>


More information about the cfe-commits mailing list