1 // RUN: %check_clang_tidy %s bugprone-implicit-widening-of-multiplication-result %t -- \
2 // RUN:     -config='{CheckOptions: { \
3 // RUN:         bugprone-implicit-widening-of-multiplication-result.IgnoreConstantIntExpr: true \
4 // RUN:     }}' -- -target x86_64-unknown-unknown -x c++
5 
6 long t0() {
7   return 1 * 4;
8 }
9 
10 unsigned long t1() {
11   const int a = 2;
12   const int b = 3;
13   return a * b;
14 }
15 
16 long t2() {
17   constexpr int a = 16383; // ~1/2 of int16_t max
18   constexpr int b = 2;
19   return a * b;
20 }
21 
22 constexpr int global_value() {
23   return 16;
24 }
25 
26 unsigned long t3() {
27   constexpr int a = 3;
28   return a * global_value();
29 }
30 
31 long t4() {
32   const char a = 3;
33   const short b = 2;
34   const int c = 5;
35   return c * b * a;
36 }
37 
38 long t5() {
39   constexpr int min_int = (-2147483647 - 1); // A literal of -2147483648 evaluates to long
40   return 1 * min_int;
41 }
42 
43 unsigned long n0() {
44   const int a = 1073741824; // 1/2 of int32_t max
45   const int b = 3;
46   return a * b;
47   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'int'
48   // CHECK-MESSAGES: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning
49   // CHECK-MESSAGES:                  static_cast<unsigned long>( )
50   // CHECK-MESSAGES: :[[@LINE-4]]:10: note: perform multiplication in a wider type
51 }
52 
53 double n1() {
54   const long a = 100000000;
55   return a * 400;
56 }
57