[cfe-commits] [PATCH] Reword an "expected unqualified-id" error to something more helpful

Eric Christopher echristo at gmail.com
Mon Jan 14 14:56:03 PST 2013


*cheers*

-eric


On Mon, Jan 14, 2013 at 2:51 PM, Richard Trieu <rtrieu at google.com> wrote:

> Currently, "int->get();" or "int.get();" gives the vague error of
> "expected unqualified-id".  The proposed error message is "cannot use arrow
> operator on a type" or "cannot use dot operator on a type".
>
> http://llvm-reviews.chandlerc.com/D297
>
> 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
> @@ -4483,9 +4483,12 @@
>      if (D.getContext() == Declarator::MemberContext)
>        Diag(Tok, diag::err_expected_member_name_or_semi)
>          << D.getDeclSpec().getSourceRange();
> -    else if (getLangOpts().CPlusPlus)
> -      Diag(Tok, diag::err_expected_unqualified_id) <<
> getLangOpts().CPlusPlus;
> -    else
> +    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
>        Diag(Tok, diag::err_expected_ident_lparen);
>      D.SetIdentifier(0, Tok.getLocation());
>      D.setInvalidType(true);
> Index: test/Parser/cxx-decl.cpp
> ===================================================================
> --- test/Parser/cxx-decl.cpp
> +++ test/Parser/cxx-decl.cpp
> @@ -132,6 +132,24 @@
>    typedef S() : n(1), m(2) { } // expected-error {{function definition
> declared 'typedef'}}
>  };
>
> +struct DIE {
> +  void foo() {}
> +};
> +
> +void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) {
> +  DIE.foo();  // expected-error {{cannot use dot operator on a type}}
> +  die.foo();
> +
> +  DIE->foo();  // expected-error {{cannot use arrow operator on a type}}
> +  Die->foo();
> +
> +  int.foo();  // expected-error {{cannot use dot operator on a type}}
> +  INT.foo();
> +
> +  float->foo();  // expected-error {{cannot use arrow operator on a type}}
> +  FLOAT->foo();
> +}
> +
>  // PR8380
>  extern ""      // expected-error {{unknown linkage language}}
>  test6a { ;// expected-error {{C++ requires a type specifier for all
> declarations}} \
> Index: include/clang/Basic/DiagnosticParseKinds.td
> ===================================================================
> --- include/clang/Basic/DiagnosticParseKinds.td
> +++ include/clang/Basic/DiagnosticParseKinds.td
> @@ -422,6 +422,8 @@
>  def err_no_matching_param : Error<"parameter named %0 is missing">;
>
>  /// C++ parser diagnostics
> +def err_invalid_operator_on_type : Error<
> +  "cannot use %select{dot|arrow}0 operator on a type">;
>  def err_expected_unqualified_id : Error<
>    "expected %select{identifier|unqualified-id}0">;
>  def err_func_def_no_params : Error<
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130114/88f8c76a/attachment.html>


More information about the cfe-commits mailing list