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