diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2013-12-05 23:06:53 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2013-12-05 23:06:53 +0000 |
commit | e6ac50ad71b7dd63e5b746fce9eb3a1e76debb01 (patch) | |
tree | d37767ec45aaa7ae24fc116fdfa335cd0f320408 /clang/test/Sema/warn-outof-range-assign-enum.c | |
parent | 00fe87b4888b230325edd96a4c2df866d91da64e (diff) | |
download | bcm5719-llvm-e6ac50ad71b7dd63e5b746fce9eb3a1e76debb01.tar.gz bcm5719-llvm-e6ac50ad71b7dd63e5b746fce9eb3a1e76debb01.zip |
-Wassign-enum: compare unqualified types
This commit changes -Wassign-enum to compare unqualified types. One could
think that this does not matter much, because who wants a value of enum type
that is const-qualified? But this breaks the intended pattern to silence this
warning with an explicit cast:
static const enum Foo z = (enum Foo) 42;
In this case, source type is 'enum Foo', and destination type is 'const enum
Foo', and if we compare qualified types, they don't match, so we used warn.
llvm-svn: 196548
Diffstat (limited to 'clang/test/Sema/warn-outof-range-assign-enum.c')
-rw-r--r-- | clang/test/Sema/warn-outof-range-assign-enum.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/Sema/warn-outof-range-assign-enum.c b/clang/test/Sema/warn-outof-range-assign-enum.c index 43eea0cef41..edd4e372292 100644 --- a/clang/test/Sema/warn-outof-range-assign-enum.c +++ b/clang/test/Sema/warn-outof-range-assign-enum.c @@ -11,6 +11,24 @@ typedef enum CCTestEnum CCTestEnum test = 50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} CCTestEnum test1 = -50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} +// Explicit cast should silence the warning. +static const CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} +static const CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning +static const CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning +static const CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning + +void SilenceWithCastLocalVar() { + CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} + CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning + CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning + CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning + + const CCTestEnum SilenceWithCast1c = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} + const CCTestEnum SilenceWithCast2c = (CCTestEnum) 51; // no-warning + const CCTestEnum SilenceWithCast3c = (const CCTestEnum) 51; // no-warning + const CCTestEnum SilenceWithCast4c = (const volatile CCTestEnum) 51; // no-warning +} + CCTestEnum foo(CCTestEnum r) { return 20; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} } |