[PATCH] new check checking use of identical expressions inside a conditional expression, i.e. '?'.
Per Viberg
Per.Viberg at evidente.se
Fri Nov 15 02:02:01 PST 2013
Hi,
This patch adds a check that warns for usage of identical expressions inside a conditional expression, i.e. '?'.
example:
unsigned a = 1;
unsigned b = 2;
unsigned c = a > 5 ? a+b : a+b;
generates warning
"identical expressions on both sides of ':' in conditional expression"
see test file identical-expression.cpp for more details.
Benchmarking results:
LLVM/Clang build time:
time without check: 17415.63 seconds (scan-build --use-analyzer clang -enable-checker)
time without check: 17508.07 seconds (scan-build --use-analyzer clang -enable-checker alpha.core.IdenticalExpr)
increase: 92,44 seconds
increase in percent: 0.53 % (IdenticalExpr includes check for of use of identical expressions with comparison operators as well).
Validation results:
Run check on selected open source C/C++ projects:
LLVM/Clang --> no positives, false or true.
cppchecker --> no positives, false or true.
redis --> no positives, false or true.
rethinkdb --> no positives, false or true.
Verification results:
Tested against identical-expressions.cpp: no failed tests.
(see test file: identical-expression.cpp)
Best regards,
Per
.......................................................................................................................
Per Viberg Senior Engineer
Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden
Phone: +46 (0)8 402 79 00
Mobile: +46 (0)70 912 42 52
E-mail: Per.Viberg at evidente.se
www.evidente.se
This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: IdenticalExprCondOperator_rev5.diff
Type: text/x-patch
Size: 7066 bytes
Desc: IdenticalExprCondOperator_rev5.diff
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131115/c5ed2fae/attachment.bin>
More information about the cfe-commits
mailing list