From 9c67267a7bcedd38ceb0b38719f4008f57bb0039 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Sat, 26 Jan 2013 02:31:38 +0000 Subject: [PATCH] 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". llvm-svn: 173556 --- clang/include/clang/Basic/DiagnosticParseKinds.td | 2 ++ clang/lib/Parse/ParseDecl.cpp | 9 ++++++--- clang/test/Parser/cxx-decl.cpp | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 055e79c..474428e 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -422,6 +422,8 @@ def err_declaration_does_not_declare_param : Error< 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< diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index cfe5d1b..6acb0b2 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4498,9 +4498,12 @@ void Parser::ParseDirectDeclarator(Declarator &D) { 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); diff --git a/clang/test/Parser/cxx-decl.cpp b/clang/test/Parser/cxx-decl.cpp index ee292fd..71fd7aa 100644 --- a/clang/test/Parser/cxx-decl.cpp +++ b/clang/test/Parser/cxx-decl.cpp @@ -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}} \ -- 2.7.4