brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · d7ab8a7 Raw
57 lines · cpp
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 6long t0() {7  return 1 * 4;8}9 10unsigned long t1() {11  const int a = 2;12  const int b = 3;13  return a * b;14}15 16long t2() {17  constexpr int a = 16383; // ~1/2 of int16_t max18  constexpr int b = 2;19  return a * b;20}21 22constexpr int global_value() {23  return 16;24}25 26unsigned long t3() {27  constexpr int a = 3;28  return a * global_value();29}30 31long t4() {32  const char a = 3;33  const short b = 2;34  const int c = 5;35  return c * b * a;36}37 38long t5() {39  constexpr int min_int = (-2147483647 - 1); // A literal of -2147483648 evaluates to long40  return 1 * min_int;41}42 43unsigned long n0() {44  const int a = 1073741824; // 1/2 of int32_t max45  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 warning49  // CHECK-MESSAGES:                  static_cast<unsigned long>( )50  // CHECK-MESSAGES: :[[@LINE-4]]:10: note: perform multiplication in a wider type51}52 53double n1() {54  const long a = 100000000;55  return a * 400;56}57