[cfe-dev] clang does not check for assignment of integers to enums
jahanian
fjahanian at apple.com
Mon Jul 16 15:29:59 PDT 2012
In clang for c/objc, assignment of out-of-range integer values to an enum variable does not raise a warning; whereas use of an out-of-range integer value in a
switch case does raise a warning. This test fails to issue any warning.
typedef enum CCTestEnum
{
One,
Two,
Three
} CCTestEnum;
CCTestEnum foo() {
CCTestEnum test = 3; // no warning
return 3; // no warning
}
Is there a reason that his warning is not being issued? On the surface, it looks like a very useful warning.
I am in the process of preparing a patch, which causes this test in clang to issue a warning (test says it should not).
Is there rational for not issuing such warnings?
// From test/Sema/constant-conversion.c
enum Test2 { K_zero, K_one };
enum Test2 test2(enum Test2 *t) {
*t = 20;
return 10; // shouldn't warn
}
- Thanks, Fariborz
More information about the cfe-dev
mailing list