forked from OSchip/llvm-project
Check that an overloaded function name, when used by the ! operator,
actually resolves to a particular function. Fixes PR8181, from Faisal Vali! llvm-svn: 114331
This commit is contained in:
parent
433d7741bd
commit
db8c6fd18f
|
@ -6814,6 +6814,13 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc,
|
|||
if (!resultType->isScalarType()) // C99 6.5.3.3p1
|
||||
return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
|
||||
<< resultType << Input->getSourceRange());
|
||||
|
||||
// Do not accept &f if f is overloaded
|
||||
// i.e. void f(int); void f(char); bool b = &f;
|
||||
if (resultType == Context.OverloadTy &&
|
||||
PerformContextuallyConvertToBool(Input))
|
||||
return ExprError(); // Diagnostic is uttered above
|
||||
|
||||
// LNot always has type int. C99 6.5.3.3p5.
|
||||
// In C++, it's bool. C++ 5.3.1p8
|
||||
resultType = getLangOptions().CPlusPlus ? Context.BoolTy : Context.IntTy;
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
||||
|
||||
// -- prvalue of arithmetic
|
||||
|
||||
bool b = !0;
|
||||
|
||||
bool b2 = !1.2;
|
||||
|
||||
bool b3 = !4;
|
||||
|
||||
// -- unscoped enumeration
|
||||
enum { E, F };
|
||||
|
||||
bool b4 = !E;
|
||||
bool b5 = !F;
|
||||
|
||||
// -- pointer,
|
||||
bool b6 = !&b4;
|
||||
void f();
|
||||
bool b61 = !&f;
|
||||
|
||||
// -- or pointer to member type can be converted to a prvalue of type bool.
|
||||
struct S { void f() { } };
|
||||
|
||||
bool b7 = !&S::f;
|
||||
|
||||
|
||||
bool b8 = !S(); //expected-error {{invalid argument type 'S'}}
|
||||
|
||||
namespace PR8181
|
||||
{
|
||||
void f() { }
|
||||
void f(char) { }
|
||||
bool b = !&f; //expected-error {{value of type '<overloaded function type>' is not contextually convertible to 'bool'}}
|
||||
|
||||
}
|
Loading…
Reference in New Issue