forked from OSchip/llvm-project
A few minor improvements to error recovery trying to access member of a function. In particular, this restores the cool error recovery for the example from http://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.html , which regressed a few months back.
llvm-svn: 148089
This commit is contained in:
parent
90b748e0d1
commit
9a766c4043
|
@ -3442,7 +3442,7 @@ def err_typecheck_member_reference_unknown : Error<
|
|||
"cannot refer to member %0 in %1 with '%select{.|->}2'">;
|
||||
def err_member_reference_needs_call : Error<
|
||||
"base of member reference is a function; perhaps you meant to call "
|
||||
"it%select{| with no arguments}?">;
|
||||
"it%select{| with no arguments}0?">;
|
||||
def warn_subscript_is_char : Warning<"array subscript is of type 'char'">,
|
||||
InGroup<CharSubscript>, DefaultIgnore;
|
||||
|
||||
|
|
|
@ -976,12 +976,10 @@ static bool isPointerToRecordType(QualType T) {
|
|||
/// Perform conversions on the LHS of a member access expression.
|
||||
ExprResult
|
||||
Sema::PerformMemberExprBaseConversion(Expr *Base, bool IsArrow) {
|
||||
ExprResult BaseResult = DefaultFunctionArrayConversion(Base);
|
||||
if (IsArrow && !Base->getType()->isFunctionType())
|
||||
return DefaultFunctionArrayLvalueConversion(Base);
|
||||
|
||||
if (!BaseResult.isInvalid() && IsArrow)
|
||||
BaseResult = DefaultLvalueConversion(BaseResult.take());
|
||||
|
||||
return BaseResult;
|
||||
return CheckPlaceholderExpr(Base);
|
||||
}
|
||||
|
||||
/// Look up the given member of the given non-type-dependent
|
||||
|
@ -1033,7 +1031,7 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
|
|||
<< BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
|
||||
<< FixItHint::CreateReplacement(OpLoc, ".");
|
||||
IsArrow = false;
|
||||
} else if (BaseType == Context.BoundMemberTy) {
|
||||
} else if (BaseType->isFunctionType()) {
|
||||
goto fail;
|
||||
} else {
|
||||
Diag(MemberLoc, diag::err_typecheck_member_reference_arrow)
|
||||
|
@ -1365,7 +1363,7 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
|
|||
if (tryToRecoverWithCall(BaseExpr,
|
||||
PDiag(diag::err_member_reference_needs_call),
|
||||
/*complain*/ false,
|
||||
IsArrow ? &isRecordType : &isPointerToRecordType)) {
|
||||
IsArrow ? &isPointerToRecordType : &isRecordType)) {
|
||||
if (BaseExpr.isInvalid())
|
||||
return ExprError();
|
||||
BaseExpr = DefaultFunctionArrayConversion(BaseExpr.take());
|
||||
|
|
|
@ -147,3 +147,13 @@ namespace PR9025 {
|
|||
return fun5.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}}
|
||||
}
|
||||
}
|
||||
|
||||
namespace FuncInMemberExpr {
|
||||
struct Vec { int size(); };
|
||||
Vec fun1();
|
||||
int test1() { return fun1.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
|
||||
Vec *fun2();
|
||||
int test2() { return fun2->size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
|
||||
Vec fun3(int x = 0);
|
||||
int test3() { return fun3.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue