If the user is trying to apply the -> or . member reference operator
to a function or function pointer, it's probably because the user
forgot to put in parentheses () to call the function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67826 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 8922abd..8b646e9 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2101,9 +2101,22 @@
MemberLoc));
}
- return ExprError(Diag(MemberLoc,
- diag::err_typecheck_member_reference_struct_union)
- << BaseType << BaseExpr->getSourceRange());
+ Diag(MemberLoc, diag::err_typecheck_member_reference_struct_union)
+ << BaseType << BaseExpr->getSourceRange();
+
+ // If the user is trying to apply -> or . to a function or function
+ // pointer, it's probably because they forgot parentheses to call
+ // the function. Suggest the addition of those parentheses.
+ if (BaseType == Context.OverloadTy ||
+ BaseType->isFunctionType() ||
+ (BaseType->isPointerType() &&
+ BaseType->getAsPointerType()->isFunctionType())) {
+ SourceLocation Loc = PP.getLocForEndOfToken(BaseExpr->getLocEnd());
+ Diag(Loc, diag::note_member_reference_needs_call)
+ << CodeModificationHint::CreateInsertion(Loc, "()");
+ }
+
+ return ExprError();
}
/// ConvertArgumentsForCall - Converts the arguments specified in