1// RUN: %check_clang_tidy %s cppcoreguidelines-narrowing-conversions %t \
2// RUN: -config="{CheckOptions: { \
3// RUN: cppcoreguidelines-narrowing-conversions.PedanticMode: true}}" \
4// RUN: -- -target x86_64-unknown-linux -fsigned-char
5
6namespace floats {
7
8void triggers_wrong_constant_type_warning(double d) {
9 int i = 0.0;
10 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: constant value should be of type of type 'int' instead of 'double' [cppcoreguidelines-narrowing-conversions]
11 i += 2.0;
12 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constant value should be of type of type 'int' instead of 'double' [cppcoreguidelines-narrowing-conversions]
13 i += 2.0f;
14 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constant value should be of type of type 'int' instead of 'float' [cppcoreguidelines-narrowing-conversions]
15}
16
17void triggers_narrowing_warning_when_overflowing() {
18 unsigned short us = 65537.0;
19 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: narrowing conversion from constant 'double' to 'unsigned short' [cppcoreguidelines-narrowing-conversions]
20}
21
22} // namespace floats
23

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