38 lines · c
1// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional %s2// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare-conditional %s3 4enum ro { A = 0x10 };5enum rw { B = 0xFF };6enum { C = 0x1A};7 8enum {9 STATUS_SUCCESS,10 STATUS_FAILURE,11 MAX_BASE_STATUS_CODE12};13 14enum ExtendedStatusCodes {15 STATUS_SOMETHING_INTERESTING = MAX_BASE_STATUS_CODE + 1000,16};17 18 19int get_flag(int cond) {20 return cond ? A : B; 21 #ifdef __cplusplus22 // 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 #endif26}27 28// In the following cases we purposefully differ from GCC and dont warn because29// this code pattern is quite sensitive and we dont want to produce so many false positives.30 31int get_flag_anon_enum(int cond) {32 return cond ? A : C;33}34 35int foo(int c) {36 return c ? STATUS_SOMETHING_INTERESTING : STATUS_SUCCESS;37}38