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 
get_flag(int cond)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-no-diagnostics
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 
get_flag_anon_enum(int cond)31 int get_flag_anon_enum(int cond) {
32   return cond ? A : C;
33 }
34 
foo(int c)35 int foo(int c) {
36   return c ? STATUS_SOMETHING_INTERESTING : STATUS_SUCCESS;
37 }
38