128 lines · c
1// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only \2// RUN: -Wtautological-unsigned-enum-zero-compare \3// RUN: -verify=unsigned,unsigned-signed %s4// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only \5// RUN: -Wtautological-unsigned-enum-zero-compare \6// RUN: -verify=unsigned-signed %s7// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only \8// RUN: -verify=silence %s9 10// Okay, this is where it gets complicated.11// Then default enum sigdness is target-specific.12// On windows, it is signed by default. We do not want to warn in that case.13 14int main(void) {15 enum A { A_a = 0 };16 enum A a;17 enum B { B_a = -1 };18 enum B b;19 20 // silence-no-diagnostics21 22 if (a < 0) // unsigned-warning {{comparison of unsigned enum expression < 0 is always false}}23 return 0;24 if (0 >= a)25 return 0;26 if (a > 0)27 return 0;28 if (0 <= a) // unsigned-warning {{comparison of 0 <= unsigned enum expression is always true}}29 return 0;30 if (a <= 0)31 return 0;32 if (0 > a) // unsigned-warning {{comparison of 0 > unsigned enum expression is always false}}33 return 0;34 if (a >= 0) // unsigned-warning {{comparison of unsigned enum expression >= 0 is always true}}35 return 0;36 if (0 < a)37 return 0;38 39 if (a < 0U) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}40 return 0;41 if (0U >= a)42 return 0;43 if (a > 0U)44 return 0;45 if (0U <= a) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}46 return 0;47 if (a <= 0U)48 return 0;49 if (0U > a) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}50 return 0;51 if (a >= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}52 return 0;53 if (0U < a)54 return 0;55 56 if (b < 0)57 return 0;58 if (0 >= b)59 return 0;60 if (b > 0)61 return 0;62 if (0 <= b)63 return 0;64 if (b <= 0)65 return 0;66 if (0 > b)67 return 0;68 if (b >= 0)69 return 0;70 if (0 < b)71 return 0;72 73 if (b < 0U) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}74 return 0;75 if (0U >= b)76 return 0;77 if (b > 0U)78 return 0;79 if (0U <= b) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}80 return 0;81 if (b <= 0U)82 return 0;83 if (0U > b) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}84 return 0;85 if (b >= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}86 return 0;87 if (0U < b)88 return 0;89 90 if (a == 0)91 return 0;92 if (0 != a)93 return 0;94 if (a != 0)95 return 0;96 if (0 == a)97 return 0;98 99 if (a == 0U)100 return 0;101 if (0U != a)102 return 0;103 if (a != 0U)104 return 0;105 if (0U == a)106 return 0;107 108 if (b == 0)109 return 0;110 if (0 != b)111 return 0;112 if (b != 0)113 return 0;114 if (0 == b)115 return 0;116 117 if (b == 0U)118 return 0;119 if (0U != b)120 return 0;121 if (b != 0U)122 return 0;123 if (0U == b)124 return 0;125 126 return 1;127}128