llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.12k stars 12.01k forks source link

Clang doesn't issue errors for builtin operators, picked by overloading #16405

Open llvmbot opened 11 years ago

llvmbot commented 11 years ago
Bugzilla Link 16033
Version trunk
OS Windows NT
Attachments code example
Reporter LLVM Bugzilla Contributor
CC @Weverything

Extended Description

See attached code example

Weverything commented 11 years ago

int* x; x + 100.0;

This is invalid due to a pointer plus float.

struct Y { operator int*(); }; Y() + 100.0;

Overload resolution happens here, which is more permissive. For overload resolution, there exists: int operator(int, std::ptrdiff_t); which Clang find and converts the operands for. Overload resolution tends to be a bit more permissive.

Weverything commented 11 years ago

-BinaryOperator 0x6814e80 <line:24:2, col:8> 'int *' '+' |-ImplicitCastExpr 0x6814e50 <col:2, col:4> 'int *' <UserDefinedConversion> |-CXXMemberCallExpr 0x6814e28 <col:2, col:4> 'int ' | `-MemberExpr 0x6814df8 <col:2, col:4> '' .operator int 0x6812d00 | -CXXTemporaryObjectExpr 0x6814840 <col:2, col:4> 'struct Y' 'void (void)' zeroing -ImplicitCastExpr 0x6814e68 'long' `-FloatingLiteral 0x68149a0 'double' 1.000000e+02

According to the AST dump, an extra ImplicitCastExpr for FloatingToIntegral is used, which prevents the error from being emitted.