[Bug c++/17805] New: too liberal operator lookup
rth at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sun Oct 3 11:15:00 GMT 2004
struct QCString
{
QCString( int size ) {};
QCString( const char *str ) {};
};
inline bool operator==( const QCString &s1, const QCString &s2 )
{ return 0; }
enum EStyle
{
FS_SOLID
};
static EStyle getFillStyle() { return FS_SOLID; }
int main()
{
if(getFillStyle() == "FS_SOLID") {}
}
As I understand it, this is invalid code. Alex Oliva writes:
Since one of the operands of == is a class or enumerated type [13.3.1.2]/1,
user-defined operators are candidate functions. However, to avoid the very kind
of error you've observed, paragraph 3 of the same clause, that defines how the
candidate functions are selected, says, in the second bullet:
[...] if no operand has a class type, only those non-
member functions in the lookup set that have a first parameter of
type T1 or "reference to (possibly cv-qualified) T1", when T1 is an
enumeration type, or (if there is a right operand) a second parame-
ter of type T2 or "reference to (possibly cv-qualified) T2", when T2
is an enumeration type, are candidate functions.
Affects at least gcc 3.2 and forward.
--
Summary: too liberal operator lookup
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rth at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17805
More information about the Gcc-bugs
mailing list