Debian Codegraph @

clang/test/Sema/warn-conditional-enum-types-mismatch.c

raw
1 // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional %s
2 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare-conditional %s
3
4 enum ro { A = 0x10 };
5 enum rw { B = 0xFF };
6 enum { C = 0x1A};
7
8 enum {
9 STATUS_SUCCESS,
10 STATUS_FAILURE,
11 MAX_BASE_STATUS_CODE
12 };
13
14 enum ExtendedStatusCodes {
15 STATUS_SOMETHING_INTERESTING = MAX_BASE_STATUS_CODE + 1000,
16 };
17
18
19 int get_flag(int cond) {
20 return cond ? A : B;
21 #ifdef __cplusplus
22 // expected-warning@-2 {{conditional expression between different enumeration types ('ro' and 'rw')}}
23 #else
24 // expected-warning@-4 {{conditional expression between different enumeration types ('enum ro' and 'enum rw')}}
25 #endif
26 }
27
28 // In the following cases we purposefully differ from GCC and dont warn because
29 // this code pattern is quite sensitive and we dont want to produce so many false positives.
30
31 int get_flag_anon_enum(int cond) {
32 return cond ? A : C;
33 }
34
35 int foo(int c) {
36 return c ? STATUS_SOMETHING_INTERESTING : STATUS_SUCCESS;
37 }