1// RUN: %check_clang_tidy -check-suffix=DEFAULT %s \
2// RUN: cppcoreguidelines-narrowing-conversions %t -- \
3// RUN: -config='{CheckOptions: {cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion: true}}'
4
5// RUN: %check_clang_tidy -check-suffix=DISABLED %s \
6// RUN: cppcoreguidelines-narrowing-conversions %t -- \
7// RUN: -config='{CheckOptions: {cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion: false}}'
8
9void 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
18void 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

source code of clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowinginteger-option.cpp