[cfe-commits] r173556 - Give a more informative error message when the dot or arrow operator is used
David Blaikie
dblaikie at gmail.com
Fri Jan 25 22:30:43 PST 2013
On Fri, Jan 25, 2013 at 6:31 PM, Richard Trieu <rtrieu at google.com> wrote:
> Author: rtrieu
> Date: Fri Jan 25 20:31:38 2013
> New Revision: 173556
>
> URL: http://llvm.org/viewvc/llvm-project?rev=173556&view=rev
> Log:
> Give a more informative error message when the dot or arrow operator is used
> on a type. Currently, it gives a generic "expected unqualified-id" error.
> The new error message is "cannot use (dot|arrow) operator on a type".
Kaelyn - might be nice if we could go one further & see if there's a
nearby typo correction we should be doing.
> cfe/trunk/test/Parser/cxx-decl.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=173556&r1=173555&r2=173556&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Jan 25 20:31:38 2013
> @@ -422,6 +422,8 @@ def err_declaration_does_not_declare_par
> 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<
>
> Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=173556&r1=173555&r2=173556&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Jan 25 20:31:38 2013
> @@ -4498,9 +4498,12 @@ void Parser::ParseDirectDeclarator(Decla
> 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);
>
> Modified: cfe/trunk/test/Parser/cxx-decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-decl.cpp?rev=173556&r1=173555&r2=173556&view=diff
> ==============================================================================
> --- cfe/trunk/test/Parser/cxx-decl.cpp (original)
> +++ cfe/trunk/test/Parser/cxx-decl.cpp Fri Jan 25 20:31:38 2013
> @@ -162,6 +162,24 @@ bitand r2 = v;
>
> }
>
> +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}} \
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list