diff options
author | Alexander Kornienko <alexfh@google.com> | 2015-09-10 10:07:11 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2015-09-10 10:07:11 +0000 |
commit | 11d4d6446e097ef12ee106446486276e8a8c79b0 (patch) | |
tree | fbc3710e85328ba618c458b545bccd74fd7a8049 /clang-tools-extra/test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp | |
parent | 1d7f0faf93eefa7624b611cd0636a2f62f44efe9 (diff) | |
download | bcm5719-llvm-11d4d6446e097ef12ee106446486276e8a8c79b0.tar.gz bcm5719-llvm-11d4d6446e097ef12ee106446486276e8a8c79b0.zip |
[clang-tidy] Add inconsistent declaration parameter name check
This is first of series of patches, porting code from my project colobot-lint,
as I mentioned recently in cfe-dev mailing list.
This patch adds a new check in readability module:
readability-inconsistent-declaration-parameter-name. I also added appropriate
testcases and documentation.
I chose readability module, as it seems it is the best place for it.
I think I followed the rules of LLVM coding guideline, but I may have missed
something, as I usually use other code formatting style.
http://reviews.llvm.org/D12462
Patch by Piotr Dziwinski!
llvm-svn: 247261
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp b/clang-tools-extra/test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp new file mode 100644 index 00000000000..f631317ff43 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp @@ -0,0 +1,188 @@ +// RUN: %python %S/check_clang_tidy.py %s readability-inconsistent-declaration-parameter-name %t + +void consistentFunction(int a, int b, int c); +void consistentFunction(int a, int b, int c); +void consistentFunction(int a, int b, int /*c*/); +void consistentFunction(int /*c*/, int /*c*/, int /*c*/); + +////////////////////////////////////////////////////// + +// CHECK-MESSAGES: :[[@LINE+1]]:6: warning: function 'inconsistentFunction' has 2 other declarations with different parameter names [readability-inconsistent-declaration-parameter-name] +void inconsistentFunction(int a, int b, int c); +// CHECK-MESSAGES: :[[@LINE+2]]:6: note: the 1st inconsistent declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('d', 'e', 'f'), in the other declaration: ('a', 'b', 'c') +void inconsistentFunction(int d, int e, int f); +// CHECK-MESSAGES: :[[@LINE+2]]:6: note: the 2nd inconsistent declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('x', 'y', 'z'), in the other declaration: ('a', 'b', 'c') +void inconsistentFunction(int x, int y, int z); + +////////////////////////////////////////////////////// + +// CHECK-MESSAGES: :[[@LINE+4]]:6: warning: function 'inconsistentFunctionWithVisibleDefinition' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name] +// CHECK-MESSAGES: :[[@LINE+9]]:6: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+2]]:6: note: differing parameters are named here: ('a'), in definition: ('c') +// CHECK-FIXES: void inconsistentFunctionWithVisibleDefinition(int c); +void inconsistentFunctionWithVisibleDefinition(int a); +// CHECK-MESSAGES: :[[@LINE+4]]:6: warning: function 'inconsistentFunctionWithVisibleDefinition' has a definition +// CHECK-MESSAGES: :[[@LINE+4]]:6: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+2]]:6: note: differing parameters are named here: ('b'), in definition: ('c') +// CHECK-FIXES: void inconsistentFunctionWithVisibleDefinition(int c); +void inconsistentFunctionWithVisibleDefinition(int b); +void inconsistentFunctionWithVisibleDefinition(int c) { c; } + +// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function 'inconsidentFunctionWithUnreferencedParameterInDefinition' has a definition +// CHECK-MESSAGES: :[[@LINE+3]]:6: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('a'), in definition: ('b') +void inconsidentFunctionWithUnreferencedParameterInDefinition(int a); +void inconsidentFunctionWithUnreferencedParameterInDefinition(int b) {} + +////////////////////////////////////////////////////// + +struct Struct { +// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: function 'Struct::inconsistentFunction' has a definition +// CHECK-MESSAGES: :[[@LINE+6]]:14: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+2]]:8: note: differing parameters are named here: ('a'), in definition: ('b') +// CHECK-FIXES: void inconsistentFunction(int b); + void inconsistentFunction(int a); +}; + +void Struct::inconsistentFunction(int b) { b = 0; } + +////////////////////////////////////////////////////// + +struct SpecialFunctions { +// CHECK-MESSAGES: :[[@LINE+4]]:3: warning: function 'SpecialFunctions::SpecialFunctions' has a definition +// CHECK-MESSAGES: :[[@LINE+12]]:19: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+2]]:3: note: differing parameters are named here: ('a'), in definition: ('b') +// CHECK-FIXES: SpecialFunctions(int b); + SpecialFunctions(int a); + +// CHECK-MESSAGES: :[[@LINE+4]]:21: warning: function 'SpecialFunctions::operator=' has a definition +// CHECK-MESSAGES: :[[@LINE+8]]:37: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+2]]:21: note: differing parameters are named here: ('a'), in definition: ('b') +// CHECK-FIXES: SpecialFunctions& operator=(const SpecialFunctions& b); + SpecialFunctions& operator=(const SpecialFunctions& a); +}; + +SpecialFunctions::SpecialFunctions(int b) { b; } + +SpecialFunctions& SpecialFunctions::operator=(const SpecialFunctions& b) { b; return *this; } + +////////////////////////////////////////////////////// + +// CHECK-MESSAGES: :[[@LINE+5]]:6: warning: function 'templateFunctionWithSeparateDeclarationAndDefinition' has a definition +// CHECK-MESSAGES: :[[@LINE+7]]:6: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+3]]:6: note: differing parameters are named here: ('a'), in definition: ('b') +// CHECK-FIXES: void templateFunctionWithSeparateDeclarationAndDefinition(T b); +template<typename T> +void templateFunctionWithSeparateDeclarationAndDefinition(T a); + +template<typename T> +void templateFunctionWithSeparateDeclarationAndDefinition(T b) { b; } + +////////////////////////////////////////////////////// + +template<typename T> +void templateFunctionWithSpecializations(T a) { a; } + +template<> +// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSpecializations<int>' has a primary template declaration with different parameter names [readability-inconsistent-declaration-parameter-name] +// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a') +void templateFunctionWithSpecializations(int b) { b; } + +template<> +// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSpecializations<float>' has a primary template +// CHECK-MESSAGES: :[[@LINE-10]]:6: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('c'), in primary template declaration: ('a') +void templateFunctionWithSpecializations(float c) { c; } + +////////////////////////////////////////////////////// + +template<typename T> +void templateFunctionWithoutDefinitionButWithSpecialization(T a); + +template<> +// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithoutDefinitionButWithSpecialization<int>' has a primary template +// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a') +void templateFunctionWithoutDefinitionButWithSpecialization(int b) { b; } + +////////////////////////////////////////////////////// + +template<typename T> +void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(T a); + +template<> +// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSeparateSpecializationDeclarationAndDefinition<int>' has a primary template +// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a') +void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(int b); + +template<> +// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSeparateSpecializationDeclarationAndDefinition<int>' has a primary template +// CHECK-MESSAGES: :[[@LINE-10]]:6: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('c'), in primary template declaration: ('a') +void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(int c) { c; } + +////////////////////////////////////////////////////// + +template<typename T> +class ClassTemplate +{ +public: +// CHECK-MESSAGES: :[[@LINE+4]]:10: warning: function 'ClassTemplate::functionInClassTemplateWithSeparateDeclarationAndDefinition' has a definition +// CHECK-MESSAGES: :[[@LINE+7]]:24: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+2]]:10: note: differing parameters are named here: ('a'), in definition: ('b') +// CHECK-FIXES: void functionInClassTemplateWithSeparateDeclarationAndDefinition(int b); + void functionInClassTemplateWithSeparateDeclarationAndDefinition(int a); +}; + +template<typename T> +void ClassTemplate<T>::functionInClassTemplateWithSeparateDeclarationAndDefinition(int b) { b; } + +////////////////////////////////////////////////////// + +class Class +{ +public: + template<typename T> +// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: function 'Class::memberFunctionTemplateWithSeparateDeclarationAndDefinition' has a definition +// CHECK-MESSAGES: :[[@LINE+12]]:13: note: the definition seen here +// CHECK-MESSAGES: :[[@LINE+2]]:8: note: differing parameters are named here: ('a'), in definition: ('b') +// CHECK-FIXES: void memberFunctionTemplateWithSeparateDeclarationAndDefinition(T b); + void memberFunctionTemplateWithSeparateDeclarationAndDefinition(T a); + + template<typename T> + void memberFunctionTemplateWithSpecializations(T a) { a; } +}; + +////////////////////////////////////////////////////// + +template<typename T> +void Class::memberFunctionTemplateWithSeparateDeclarationAndDefinition(T b) { b; } + +////////////////////////////////////////////////////// + +template<> +// CHECK-MESSAGES: :[[@LINE+3]]:13: warning: function template specialization 'Class::memberFunctionTemplateWithSpecializations<int>' has a primary template +// CHECK-MESSAGES: :[[@LINE-12]]:8: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:13: note: differing parameters are named here: ('b'), in primary template declaration: ('a') +void Class::memberFunctionTemplateWithSpecializations(int b) { b; } + +template<> +// CHECK-MESSAGES: :[[@LINE+3]]:13: warning: function template specialization 'Class::memberFunctionTemplateWithSpecializations<float>' has a primary template +// CHECK-MESSAGES: :[[@LINE-18]]:8: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:13: note: differing parameters are named here: ('c'), in primary template declaration: ('a') +void Class::memberFunctionTemplateWithSpecializations(float c) { c; } + +////////////////////////////////////////////////////// + +#define DECLARE_FUNCTION_WITH_PARAM_NAME(function_name, param_name) \ + void function_name(int param_name) + +// CHECK-MESSAGES: :[[@LINE+1]]:34: warning: function 'macroFunction' has 1 other declaration with different parameter names [readability-inconsistent-declaration-parameter-name] +DECLARE_FUNCTION_WITH_PARAM_NAME(macroFunction, a); +// CHECK-MESSAGES: :[[@LINE+2]]:34: note: the 1st inconsistent declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:34: note: differing parameters are named here: ('b'), in the other declaration: ('a') +DECLARE_FUNCTION_WITH_PARAM_NAME(macroFunction, b); |