c++/1056: spurious warning on implicit conversion followed by promotion and comparison
martin.dorey@synaxia.com
martin.dorey@synaxia.com
Wed Dec 13 09:16:00 GMT 2000
>Number: 1056
>Category: c++
>Synopsis: spurious warning on implicit conversion followed by promotion and comparison
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Dec 13 09:16:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: martin.dorey@synaxia.com
>Release: gcc version 2.97 20001211 (experimental)
>Organization:
>Environment:
http://www.codesourcery.com/gcc-compile.shtml
>Description:
Builtin operator==() produces a spurious warning when comparing an unsigned short with an unsigned long where the unsigned short is obtained via an implicit conversion from a class object.
>How-To-Repeat:
typedef unsigned short uint16;
struct be16
{
uint16 get () const;
operator uint16 () const;
};
be16 b;
unsigned long s;
bool cat (int, int);
bool cat (int, unsigned int);
bool cat (unsigned int, int);
bool cat (unsigned int, unsigned int);
bool cat (long, long);
bool cat (long, unsigned long);
bool cat (unsigned long, unsigned long);
bool cat (unsigned long, long);
bool cat (long, int);
bool cat (long, unsigned int);
bool cat (unsigned long, int);
bool cat (unsigned long, unsigned int);
bool cat (int, long);
bool cat (int, unsigned long);
bool cat (unsigned int, unsigned long);
bool cat (unsigned int, long);
#if 0
#define CAT(a, b) cat (a, b)
#else
#define CAT(a, b) a == b
#endif
int
main()
{
extern uint16 fn();
uint16 a = fn();
if (CAT (a, b))
;
if (CAT (b, a))
;
if (CAT (a, s))
;
if (CAT (s, a))
;
if (CAT (b, s))
;
if (CAT (s, b))
;
if (CAT (b.get(), s))
;
if (CAT (s, b.get()))
;
return 0;
}
gcc -c -W -Wall produces:
/tmp/@7541.7.cc: In function `int main()':
/tmp/@7541.7.cc:51: warning: comparison between signed and unsigned integer
expressions
/tmp/@7541.7.cc:53: warning: comparison between signed and unsigned integer
expressions
Changing the #if around causes a compilation with no warnings. I haven't been able to find anything in the Standard which makes me think that the warning is justified.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list