[LLVMbugs] [Bug 22062] New: In C -Wtautological-constant-out-of-range-compare should not trigger for out of range enums
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Dec 30 04:05:24 PST 2014
http://llvm.org/bugs/show_bug.cgi?id=22062
Bug ID: 22062
Summary: In C -Wtautological-constant-out-of-range-compare
should not trigger for out of range enums
Product: clang
Version: unspecified
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: fredm at spamcop.net
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Given this code:
#include <stdio.h>
typedef enum o {
O_1 = 0,
O_2,
} o;
int main(int argc, char** argv) {
enum o e1 = -1;
if( e1 >= 2 ) {
printf( "That's not right\n" );
}
printf("e1:%d\n",e1);
return 0;
}
Clang warns as follows:
$ clang -Wall -std=c89 t1.c
t1.c:11:10: warning: comparison of constant 2 with expression of type 'enum
o'
is always false [-Wtautological-constant-out-of-range-compare]
if( e1 >= 2 ) {
~~ ^ ~
1 warning generated.
That is demonstrably untrue:
$ ./a.out
That's not right
e1:-1
I don't believe that it is correct to assert the range of an enum to be limited
to the declared values in C, while that is valid in C++.
In C an enumeration is defined as an enumeration constant and 6.4.4.3 of the
draft C standard April 12, 2011 ISO/IEC 9899:201x I am looking at says:
An identifier declared as an enumeration constant has type int.
6.7.2.2 says:
Each enumerated type shall be compatible with char, a signed integer type, or
an unsigned integer type. The choice of type is implementation-defined,128) but
shall be capable of representing the values of all the members of the
enumeration.
As long as it isn't forbidden to assign out-of-enumeration values to an
enumeration I think that it is invalid to say that the comparison of any out of
declared enumeration range value is guaranteed to be tautological.
A similar issue appeared to be raised and fixed in bug 16154.
I have raised this in the cfe-users mailing list (14-Dec-2013) where it was
suggested to raise the issue as a PR. I am not quite sure how a year passed in
the interim :)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141230/c152c5b2/attachment.html>
More information about the llvm-bugs
mailing list