[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name
Firat Kasmis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 9 09:49:14 PST 2016
firolino created this revision.
firolino added reviewers: alexfh, aaron.ballman, klimek, malcolm.parsons.
firolino added a subscriber: cfe-commits.
Herald added subscribers: JDevlieghere, mgorny.
This check can be used to find declarations, which declare more than one name.
It helps improving readability and prevents potential bugs caused by inattention
and C/C++ syntax specifics.
In addition, appropriate fix-it hints are provided and all user-intended
indentation will be preserved. For example:
{
long ** lint1, lint2 = 0, * lint3, **linn;
const int cx = 1, cy = 2;
int const CS :: * pp = &CS::a, CS::* const qq = &CS::a;
decltype(int()) declint1 = 5, declint2 = 3;
typedef int ta, tb;
}
will be transformed to:
{
long ** lint1;
long lint2 = 0;
long * lint3;
long **linn;
const int cx = 1;
const int cy = 2;
int const CS :: * pp = &CS::a;
int const CS::* const qq = &CS::a;
decltype(int()) declint1 = 5;
decltype(int()) declint2 = 3;
typdef int ta;
typdef int tb;
}
Only declarations within a compound statement are matched. Meaning, global declarations
and function parameters are not matched. Moreover, it does not match on the following:
{
class A { } Object1, Object2;
for(int i = 0, j = 0;;);
}
This check will be used for:
- CppCoreGuideline ES.10 <http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#a-nameres-name-oneaes10-declare-one-name-only-per-declaration>
- DCL04 <https://www.securecoding.cert.org/confluence/display/c/DCL04-C.+Do+not+declare+more+than+one+variable+per+declaration>
in the future and provide appropriate options for it.
https://reviews.llvm.org/D27621
Files:
clang-tidy/readability/CMakeLists.txt
clang-tidy/readability/OneNamePerDeclarationCheck.cpp
clang-tidy/readability/OneNamePerDeclarationCheck.h
clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tidy/utils/LexerUtils.cpp
clang-tidy/utils/LexerUtils.h
docs/clang-tidy/checks/list.rst
docs/clang-tidy/checks/readability-one-name-per-declaration.rst
test/clang-tidy/readability-one-name-per-declaration-complex.cpp
test/clang-tidy/readability-one-name-per-declaration-modern.cpp
test/clang-tidy/readability-one-name-per-declaration-simple.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27621.80912.patch
Type: text/x-patch
Size: 36635 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161209/3df33ee1/attachment-0001.bin>
More information about the cfe-commits
mailing list