sammccall created this revision. Herald added subscribers: cfe-commits, xazax.hun.
The goal is to reduce false positives when the difference is intentional, like: foo(StringRef name); foo(StringRef name_ref) { string name = cleanup(name_ref); ... } Or semantically unimportant, like: foo(StringRef full_name); foo(StringRef name) { ... } There are other matching names we won't recognise (e.g. syns vs synonyms) but this catches many that we see in practice, and gives people a systematic workaround. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D49285 Files: clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp Index: test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp =================================================================== --- test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp +++ test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp @@ -2,6 +2,8 @@ void consistentFunction(int a, int b, int c); void consistentFunction(int a, int b, int c); +void consistentFunction(int prefixA, int inBFix, int cSuffix); +void consistentFunction(int a, int b, int c); void consistentFunction(int a, int b, int /*c*/); void consistentFunction(int /*c*/, int /*c*/, int /*c*/); Index: clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp =================================================================== --- clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp +++ clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp @@ -90,6 +90,12 @@ return true; } +// We allow two names if one is a substring of the other, ignoring case. +// Important special case: this is true if either parameter has no name! +bool nameMatch(StringRef L, StringRef R) { + return L.contains_lower(R) || R.contains_lower(L); +} + DifferingParamsContainer findDifferingParamsInDeclaration(const FunctionDecl *ParameterSourceDeclaration, const FunctionDecl *OtherDeclaration, @@ -106,8 +112,7 @@ // FIXME: Provide a way to extract commented out parameter name from comment // next to it. - if (!SourceParamName.empty() && !OtherParamName.empty() && - SourceParamName != OtherParamName) { + if (!nameMatch(SourceParamName, OtherParamName)) { SourceRange OtherParamNameRange = DeclarationNameInfo((*OtherParamIt)->getDeclName(), (*OtherParamIt)->getLocation())
Index: test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp =================================================================== --- test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp +++ test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp @@ -2,6 +2,8 @@ void consistentFunction(int a, int b, int c); void consistentFunction(int a, int b, int c); +void consistentFunction(int prefixA, int inBFix, int cSuffix); +void consistentFunction(int a, int b, int c); void consistentFunction(int a, int b, int /*c*/); void consistentFunction(int /*c*/, int /*c*/, int /*c*/); Index: clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp =================================================================== --- clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp +++ clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp @@ -90,6 +90,12 @@ return true; } +// We allow two names if one is a substring of the other, ignoring case. +// Important special case: this is true if either parameter has no name! +bool nameMatch(StringRef L, StringRef R) { + return L.contains_lower(R) || R.contains_lower(L); +} + DifferingParamsContainer findDifferingParamsInDeclaration(const FunctionDecl *ParameterSourceDeclaration, const FunctionDecl *OtherDeclaration, @@ -106,8 +112,7 @@ // FIXME: Provide a way to extract commented out parameter name from comment // next to it. - if (!SourceParamName.empty() && !OtherParamName.empty() && - SourceParamName != OtherParamName) { + if (!nameMatch(SourceParamName, OtherParamName)) { SourceRange OtherParamNameRange = DeclarationNameInfo((*OtherParamIt)->getDeclName(), (*OtherParamIt)->getLocation())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits