78 lines · c
1// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -Wsign-compare %s2// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -verify -Wsign-compare %s3// RUN: %clang_cc1 -x c++ -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -Wsign-compare %s4// RUN: %clang_cc1 -x c++ -triple=x86_64-pc-win32 -fsyntax-only -verify -Wsign-compare %s5 6// Check that -Wsign-compare is off by default.7// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -DSILENCE %s8 9#ifdef SILENCE10// expected-no-diagnostics11#endif12 13enum PosEnum {14 A_a = 0,15 A_b = 1,16 A_c = 1017};18 19static const int message[] = {0, 1};20 21int test_pos(enum PosEnum a) {22 if (a < 2)23 return 0;24 25 // No warning, except in Windows C mode, where PosEnum is 'int' and it can26 // take on any value according to the C standard.27#if !defined(SILENCE) && defined(_WIN32) && !defined(__cplusplus)28 // expected-warning@+2 {{comparison of integers of different signs}}29#endif30 if (a < 2U)31 return 0;32 33 unsigned uv = 2;34#if !defined(SILENCE) && defined(_WIN32) && !defined(__cplusplus)35 // expected-warning@+2 {{comparison of integers of different signs}}36#endif37 if (a < uv)38 return 1;39 40#if !defined(SILENCE) && defined(_WIN32) && !defined(__cplusplus)41 // expected-warning@+2 {{comparison of integers of different signs}}42#endif43 if (a < sizeof(message)/sizeof(message[0]))44 return 0;45 return 4;46}47 48enum NegEnum {49 NE_a = -1,50 NE_b = 0,51 NE_c = 1052};53 54int test_neg(enum NegEnum a) {55 if (a < 2)56 return 0;57 58#ifndef SILENCE59 // expected-warning@+2 {{comparison of integers of different signs}}60#endif61 if (a < 2U)62 return 0;63 64 unsigned uv = 2;65#ifndef SILENCE66 // expected-warning@+2 {{comparison of integers of different signs}}67#endif68 if (a < uv)69 return 1;70 71#ifndef SILENCE72 // expected-warning@+2 {{comparison of integers of different signs}}73#endif74 if (a < sizeof(message)/sizeof(message[0]))75 return 0;76 return 4;77}78