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