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
This commit is contained in:
Richard Trieu 2013-01-26 02:31:38 +00:00
parent 2995077d8a
commit 9c67267a7b
3 changed files with 26 additions and 3 deletions

View File

@ -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<

View File

@ -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);

View File

@ -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}} \