1 // RUN: %check_clang_tidy -check-suffix=DEFAULT %s \ 2 // RUN: cppcoreguidelines-narrowing-conversions %t -- \ 3 // RUN: -config='{CheckOptions: [{key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion, value: true}]}' 4 5 // RUN: %check_clang_tidy -check-suffix=DISABLED %s \ 6 // RUN: cppcoreguidelines-narrowing-conversions %t -- \ 7 // RUN: -config='{CheckOptions: [{key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion, value: false}]}' 8 9 void foo(unsigned long long value) { 10 int a = value; 11 // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:11: warning: narrowing conversion from 'unsigned long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] 12 // DISABLED: No warning for integer narrowing conversions when WarnOnIntegerNarrowingConversion = false. 13 long long b = value; 14 // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:17: warning: narrowing conversion from 'unsigned long long' to signed type 'long long' is implementation-defined [cppcoreguidelines-narrowing-conversions] 15 // DISABLED: No warning for integer narrowing conversions when WarnOnIntegerNarrowingConversion = false. 16 } 17 18 void casting_float_to_bool_is_still_operational_when_integer_narrowing_is_disabled(float f) { 19 if (f) { 20 // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'bool' [cppcoreguidelines-narrowing-conversions] 21 // CHECK-MESSAGES-DISABLED: :[[@LINE-2]]:7: warning: narrowing conversion from 'float' to 'bool' [cppcoreguidelines-narrowing-conversions] 22 } 23 } 24