123 lines · cpp
1// RUN: %check_clang_tidy -check-suffixes=ALL,C -std=c99 %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown -x c2// RUN: %check_clang_tidy -check-suffixes=ALL,CXX %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown -x c++3 4// RUN: %check_clang_tidy -check-suffixes=ALL,C -std=c99 %s bugprone-implicit-widening-of-multiplication-result %t -- \5// RUN: -config='{CheckOptions: { \6// RUN: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources: false \7// RUN: }}' -- -target x86_64-unknown-unknown -x c8// RUN: %check_clang_tidy -check-suffixes=ALL,C %s bugprone-implicit-widening-of-multiplication-result %t -- \9// RUN: -config='{CheckOptions: { \10// RUN: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources: false \11// RUN: }}' -- -target x86_64-unknown-unknown -x c++12 13long t0(int a, int b) {14 return a * b;15 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'int'16 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning17 // CHECK-NOTES-C: (long)( )18 // CHECK-NOTES-CXX: static_cast<long>( )19 // CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type20 // CHECK-NOTES-C: (long)21 // CHECK-NOTES-CXX: static_cast<long>( )22}23unsigned long t1(int a, int b) {24 return a * b;25 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'int'26 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning27 // CHECK-NOTES-C: (unsigned long)( )28 // CHECK-NOTES-CXX: static_cast<unsigned long>( )29 // CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type30 // CHECK-NOTES-C: (long)31 // CHECK-NOTES-CXX: static_cast<long>( )32}33 34long t2(unsigned int a, int b) {35 return a * b;36 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'unsigned int'37 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning38 // CHECK-NOTES-C: (long)( )39 // CHECK-NOTES-CXX: static_cast<long>( )40 // CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type41 // CHECK-NOTES-C: (unsigned long)42 // CHECK-NOTES-CXX: static_cast<unsigned long>( )43}44unsigned long t3(unsigned int a, int b) {45 return a * b;46 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'unsigned int'47 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning48 // CHECK-NOTES-C: (unsigned long)( )49 // CHECK-NOTES-CXX: static_cast<unsigned long>( )50 // CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type51 // CHECK-NOTES-C: (unsigned long)52 // CHECK-NOTES-CXX: static_cast<unsigned long>( )53}54 55long t4(int a, unsigned int b) {56 return a * b;57 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'unsigned int'58 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning59 // CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type60}61unsigned long t5(int a, unsigned int b) {62 return a * b;63 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'unsigned int'64 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning65 // CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type66}67 68long t6(unsigned int a, unsigned int b) {69 return a * b;70 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'unsigned int'71 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning72 // CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type73}74unsigned long t7(unsigned int a, unsigned int b) {75 return a * b;76 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'unsigned int'77 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning78 // CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type79}80 81long t8(int a, int b) {82 return (a * b);83 // CHECK-NOTES-ALL: :[[@LINE-1]]:11: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'int'84 // CHECK-NOTES-ALL: :[[@LINE-2]]:11: note: make conversion explicit to silence this warning85 // CHECK-NOTES-ALL: :[[@LINE-3]]:11: note: perform multiplication in a wider type86}87long t9(int a, int b) {88 return (a)*b;89 // CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'int'90 // CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning91 // CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type92}93long n10(int a, int b) {94 return (long)(a * b);95}96long n11(int a, int b) {97 return (unsigned long)(a * b);98}99 100long n12(long a, int b) {101 return a * b;102}103long n13(int a, long b) {104 return a * b;105}106 107long n14(int a, int b, int c) {108 return a + b * c;109}110long n15(int a, int b, int c) {111 return a * b + c;112}113 114#ifdef __cplusplus115template <typename T1, typename T2>116T2 template_test(T1 a, T1 b) {117 return a * b;118}119long template_test_instantiation(int a, int b) {120 return template_test<int, long>(a, b);121}122#endif123