Diagnose misuse of '.*' and '->*' operators during parse

instead of crashing in code gen.

llvm-svn: 84968
This commit is contained in:
Fariborz Jahanian 2009-10-23 21:01:39 +00:00
parent 61ade25834
commit 9a14b84ac5
4 changed files with 28 additions and 2 deletions

View File

@ -117,6 +117,8 @@ def err_expected_semi_after_static_assert : Error<
"expected ';' after static_assert">;
def err_expected_semi_for : Error<"expected ';' in 'for' statement specifier">;
def err_expected_colon_after : Error<"expected ':' after %0">;
def err_pointer_to_member_type : Error<
"invalid use of pointer to member type after %0">;
def err_label_end_of_compound_statement : Error<
"label at end of compound statement: expected statement">;
def err_expected_string_literal : Error<"expected string literal">;

View File

@ -340,7 +340,18 @@ Parser::ParseRHSOfBinaryExpression(OwningExprResult LHS, unsigned MinPrec) {
// Eat the colon.
ColonLoc = ConsumeToken();
}
if ((OpToken.is(tok::periodstar) || OpToken.is(tok::arrowstar))
&& Tok.is(tok::identifier)) {
CXXScopeSpec SS;
if (Actions.getTypeName(*Tok.getIdentifierInfo(),
Tok.getLocation(), CurScope, &SS)) {
const char *Opc = OpToken.is(tok::periodstar) ? "'.*'" : "'->*'";
Diag(OpToken, diag::err_pointer_to_member_type) << Opc;
return ExprError();
}
}
// Parse another leaf here for the RHS of the operator.
// ParseCastExpression works here because all RHS expressions in C have it
// as a prefix, at least. However, in C++, an assignment-expression could

View File

@ -212,7 +212,7 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
PDiag(diag::err_invalid_incomplete_type_use)
<< FullRange))
return ExprError();
if (RequireNonAbstractType(TyBeginLoc, Ty,
diag::err_allocation_of_abstract_type))
return ExprError();

View File

@ -0,0 +1,13 @@
// RUN: clang-cc -fsyntax-only -pedantic -verify %s
struct C {};
typedef void (C::*pmfc)();
void g(pmfc) {
C *c;
c->*pmfc(); // expected-error {{invalid use of pointer to member type after '->*'}}
C c1;
c1.*pmfc(); // expected-error {{invalid use of pointer to member type after '.*'}}
}