47 lines · c
1// RUN: %check_clang_tidy -std=c99,c11,c17 -check-suffixes=,BEFORE-C23 %s bugprone-easily-swappable-parameters %t \2// RUN: -config='{CheckOptions: { \3// RUN: bugprone-easily-swappable-parameters.MinimumLength: 2, \4// RUN: bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \5// RUN: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes: "", \6// RUN: bugprone-easily-swappable-parameters.QualifiersMix: 0, \7// RUN: bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \8// RUN: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 1, \9// RUN: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityThreshold: 0 \10// RUN: }}' -- -Wno-strict-prototypes -x c11//12// RUN: %check_clang_tidy -std=c23-or-later %s bugprone-easily-swappable-parameters %t \13// RUN: -config='{CheckOptions: { \14// RUN: bugprone-easily-swappable-parameters.MinimumLength: 2, \15// RUN: bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \16// RUN: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes: "", \17// RUN: bugprone-easily-swappable-parameters.QualifiersMix: 0, \18// RUN: bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \19// RUN: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 1, \20// RUN: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityThreshold: 0 \21// RUN: }}' -- -Wno-strict-prototypes -x c22 23int add(int X, int Y);24 25void notRelated(int A, int B) {}26// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'notRelated' of similar type ('int')27// CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'A'28// CHECK-MESSAGES: :[[@LINE-3]]:28: note: the last parameter in the range is 'B'29 30int addedTogether(int A, int B) { return add(A, B); } // NO-WARN: Passed to same function.31 32#if __STDC_VERSION__ < 202311L33int myprint();34void passedToSameKNRFunction(int A, int B) {35 myprint("foo", A);36 myprint("bar", B);37}38// CHECK-MESSAGES-BEFORE-C23: :[[@LINE-4]]:30: warning: 2 adjacent parameters of 'passedToSameKNRFunction' of similar type ('int')39// CHECK-MESSAGES-BEFORE-C23: :[[@LINE-5]]:34: note: the first parameter in the range is 'A'40// CHECK-MESSAGES-BEFORE-C23: :[[@LINE-6]]:41: note: the last parameter in the range is 'B'41// FIXME: This is actually a false positive: the "passed to same function" heuristic42// can't map the parameter index 1 to A and B because myprint() has no43// parameters.44// If you fix this, you should be able to combine the `%check_clang_tidy` invocations45// in this file into one and remove the `-std` and `-check-suffixes` arguments.46#endif47