1 // RUN: %check_clang_tidy -check-suffix=DEFAULT %s \
2 // RUN: cppcoreguidelines-narrowing-conversions %t -- \
3 // RUN: -config='{CheckOptions: [ \
4 // RUN: ]}'
5 
6 // RUN: %check_clang_tidy -check-suffix=DISABLED %s \
7 // RUN: cppcoreguidelines-narrowing-conversions %t -- \
8 // RUN: -config='{CheckOptions: [ \
9 // RUN:   {key: cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth, value: 0} \
10 // RUN: ]}'
11 
narrowing_equivalent_bitwidth()12 void narrowing_equivalent_bitwidth() {
13   int i;
14   unsigned int ui;
15   i = ui;
16   // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
17   // DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
18 
19   float f;
20   i = f;
21   // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
22   // DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
23 
24   f = i;
25   // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'int' to 'float' [cppcoreguidelines-narrowing-conversions]
26   // DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
27 
28   long long ll;
29   double d;
30   ll = d;
31   // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:8: warning: narrowing conversion from 'double' to 'long long' [cppcoreguidelines-narrowing-conversions]
32   // DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
33 
34   d = ll;
35   // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to 'double' [cppcoreguidelines-narrowing-conversions]
36   // DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
37 }
38 
most_narrowing_is_not_ok()39 void most_narrowing_is_not_ok() {
40   int i;
41   long long ui;
42   i = ui;
43   // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
44   // CHECK-MESSAGES-DISABLED: :[[@LINE-2]]:7: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
45 }
46