Summary:
1. Avoid converting loops that iterate over the size of a container and don't use its elements, as this would result in an unused-result warning.
2. Never capture the elements by value on lambdas, thus avoiding doing unnecessary copies and errors with non-copyable types.
3. The 'const auto &' instead of 'auto &' substitution on const containers now works on arrays and pseudoarrays as well.
4. The error about multiple replacements in the same macro call is now documented in the tests (not solved though).
5. Due to [1], I had to add a dummy usage of the range element (like "(void) *It;" or similars) on the tests that had empty loops.
6. I removed the braces from the CHECK comments. I think that there is no need for them, and they confuse vim.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D12734
llvm-svn: 247399
containers.
Summary:
sizeof(some_std_string) is likely to be an error. This check finds this
pattern and suggests using .size() instead.
Reviewers: djasper, klimek, aaron.ballman
Subscribers: aaron.ballman, cfe-commits
Differential Revision: http://reviews.llvm.org/D12759
llvm-svn: 247297
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
Do not add "-*" to the list of checks. Make consistent the list of enabled
checks and the checks in use. Moreover, removing "-*" makes the behaviour
consistent with clang-tidy and allows user to use .clang-tidy configuration...
http://reviews.llvm.org/D12687
Patch by Marek Kurdej!
llvm-svn: 247002
Summary:
When the dereference operator returns a value that is trivially
copyable (like a pointer), copy it. After this change, modernize-loop-convert
check can be applied to the whole llvm source code without breaking any build
or test.
Reviewers: alexfh, klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D12675
llvm-svn: 246989
Summary: The InitListExpr subtree is visited twice, this caused the check to do multiple replacements. Added a set to avoid it.
Reviewers: klimek, alexfh
Subscribers: cfe-commits, alexfh
Differential Revision: http://reviews.llvm.org/D12631
llvm-svn: 246879
IncludeDirectives struct used a StringRef that pointed to a stack variable
(SmallString<128> FilenameBuffer from PPDirectives.cpp:1513).
http://reviews.llvm.org/D12632
Patch by Marek Kurdej!
llvm-svn: 246856
This fixes the case where the check should be added at the end of
the list of checks in CMakeLists.txt of the corresponding module.
Before it was added after LINK_LIBS line.
http://reviews.llvm.org/D12629
Patch by Marek Kurdej!
llvm-svn: 246854
Summary: Ensure that the alias has the same type than the loop variable. Now it works with lambda captures.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D12597
llvm-svn: 246762
Summary: loop-convert no longer crashes when calling a member function using a member pointer which is a member of another record.
Reviewers: alexfh, klimek
Subscribers: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D12555
llvm-svn: 246655
Summary: Fix a bug where use-auto check would crash when the definition of a type is in the same statement than its instantiation with new.
Reviewers: alexfh
Subscribers: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D12551
llvm-svn: 246638
Summary: Reduced the amount of wrong conversions of this check.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D12530
llvm-svn: 246550
Changes mostly address formatting and unification of the style. Use
MarkDown style for inline code snippets and lists. Added some text
for a few checks.
The idea is to move most of the documentation out to separate rST files and have
implementation files refer to the corresponding documentation files.
llvm-svn: 246169
Summary: Prevent LoopConvert from taking as alias anything that comes from a random member function call.
Reviewers: alexfh
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D12370
llvm-svn: 246039
Summary: Fix a bug where modernize-loop-convert check would take as alias a reference to other containers. Add the pertinent test.
Reviewers: alexfh
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D12361
llvm-svn: 246034
Summary: Update python script, so that it doesn't print that line in new tests.
Reviewers: alexfh
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D12281
llvm-svn: 245926
While convenient, RecursiveASTVisitor generates a ridiculous amount of dead
template code. Making it not visible from the outside lets the compiler
eliminate some of it, shrinking clang-tidy by ~140k.
llvm-svn: 245548
This patch re-applies r245434 and r245471 reverted in r245493, and changes the
way custom null macros are configured. The test for custom null macros is
temporarily excluded and will be committed separately to reduce chances of
breakages.
Initial patches by Angel Garcia.
llvm-svn: 245511
Also adapt tests a bit to make it possible to test this. Removed
checking the number of errors reported per test. It was never actually
checked and doesn't seem particularly relevant to the test itself.
llvm-svn: 245500
Fix LoopConvertCheck bug: StringRef to temporaries.
Also add LLVM_ATTRIBUTE_UNUSED to ModernizeModuleAnchorDestination.
http://reviews.llvm.org/D12157
Patch by Angel Garcia!
llvm-svn: 245458
This check will try to enforce coding guidelines on the identifiers naming.
It supports lower_case, UPPER_CASE, camelBack and CamelCase casing and
tries to convert from one to another if a mismatch is detected.
It also supports a fixed prefix and suffix that will be prepended or appended
to the identifiers, regardless of the casing.
Many configuration options are available, in order to be able to create
different rules for different kind of identifier. In general, the
rules are falling back to a more generic rule if the specific case is not
configured.
http://reviews.llvm.org/D10933
Patch by Beren Minor!
llvm-svn: 245429
Summary:
The existing check converts the code pattern below:
void f()
{
}
to:
void f()
override {
}
which is fairly sub-optimal. This patch fixes this by inserting the
override keyword on the same line as the function declaration if
possible, so that we instead get:
void f() override
{
}
We do this by looking for the last token before the start of the body
and inserting the override keyword at the end of its location. Note
that we handle const, volatile and ref-qualifiers correctly.
Test Plan: Includes an automated test.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D9286
llvm-svn: 245401
Initialize CommonOptionsParser with ZeroOrOne NumOccurrenceFlag so callers can
pass -list-checks without the need to pass additional positional parameters,
then add dummy file if none were supplied.
http://reviews.llvm.org/D12070
Patch by Don Hinton!
llvm-svn: 245205
If there weren't any includes in the file, or all of them had 'IncludeKind'
greater than the desired one, then 'CreateIncludeInsertion' didn't work.
http://reviews.llvm.org/D12017
Patch by Angel Garcia!
llvm-svn: 245042
removes a corner case in tests that don't set the diagnostic consumer.
In tests, it is good, not to set the diagnostic consumer so that Clang's
parsing diagnostics are still displayed in the test output and only
ClangTidy's output is analyzed differently.
llvm-svn: 244745
Summary:
Support replacements in macro arguments in the
misc-inefficient-algorithm check.
Reviewers: klimek
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D11677
llvm-svn: 243747
As there don't seem to be a good way of formulating a matcher that
finds all pairs of functions and their ParmVarDecls, just match on
functionDecls and iterate over their parameters. This should also be
more efficient as some checks are only performed once per function.
llvm-svn: 243267
The parameters of the function templates were being marked as
incorrectly be marked as unused. Added a test for this and changed the
check to use the same
isReferenced() || !getDeclName()
logic as Sema::DiagnoseUnusedParameters.
Patch Scott Wallace, thank you!
llvm-svn: 242912
Enhance clang-tidy misc-macro-repeated-side-effects to handle ? and : better.
When ? is used in a macro, there are 2 possible control flow paths through the macro.
These paths are tracked separately so problems can be detected properly.
http://reviews.llvm.org/D10653
llvm-svn: 241245
Enhance clang-tidy readability-simplify-boolean-expr to handle 'if (e) return
true; return false;' and improve replacement expressions.
This changeset extends the simplify boolean expression check in clang-tidy to
simplify if (e) return true; return false; to return e; (note the lack of an
else clause on the if statement.) By default, chained conditional assignment is
left unchanged, unless a configuration parameter is set to non-zero to override
this behavior.
It also improves the handling of replacement expressions to apply
static_cast<bool>(expr) when expr is not of type bool.
http://reviews.llvm.org/D9810
Patch by Richard Thomson!
llvm-svn: 241155
Summary:
There were false positives in C++ code where macro argument was a type.
Reviewers: alexfh
Differential Revision: http://reviews.llvm.org/D10801
llvm-svn: 240938
Some people have reasons to compile their .c files as C++ in some configurations
(e.g. for testing purposes), so just looking at LangOptions is not enough. This
patch disables the check on all .c files (and also for the headers included from
.c files).
llvm-svn: 237905
Enhance clang-tidy readability-simplify-boolean-expr check to handle chained
conditional assignment and chained conditional return.
Based on feedback from applying this tool to the clang/LLVM codebase, this
changeset improves the readability-simplify-boolean-expr check so that
conditional assignment or return statements at the end of a chain of if/else if
statements are left unchanged unless a configuration option is supplied.
http://reviews.llvm.org/D8996
Patch by Richard Thomson!
llvm-svn: 237541
The misc-static-assert check will not warn on the followings:
assert(NULL == "shouldn't warn");
assert(__null == "shouldn't warn");
Where NULL is a macro defined as __null.
llvm-svn: 236812
The number of strings is so small that performance doesn't matter and adding
the thread safe static initialization and destruction overhead is just not
worth it. No functional change intended.
llvm-svn: 235192
This check looks for comparisons between boolean expressions and boolean
constants and simplifies them to just use the appropriate boolean expression
directly.
if (b == true) becomes if (b)
if (b == false) becomes if (!b)
if (b && true) becomes if (b)
if (b && false) becomes if (false)
if (b || true) becomes if (true)
if (b || false) becomes if (b)
e ? true : false becomes e
e ? false : true becomes !e
if (true) t(); else f(); becomes t();
if (false) t(); else f(); becomes f();
if (e) return true; else return false; becomes return (e);
if (e) return false; else return true; becomes return !(e);
if (e) b = true; else b = false; becomes b = e;
if (e) b = false; else b = true; becomes b = !(e);
http://reviews.llvm.org/D7648
Patch by Richard Thomson!
llvm-svn: 234626
Summary:
Do not warn on .reset(.release()) expressions if the deleters are not
compatible.
Using plain assignment will probably not work.
Reviewers: klimek
Subscribers: curdeius, cfe-commits
Differential Revision: http://reviews.llvm.org/D8422
llvm-svn: 234512
Use "constructors that are callable with a single argument" instead of
"single-argument constructors" when referring to constructors using default
arguments or parameter packs.
llvm-svn: 233702
Summary:
Force braces on the else branch if they are being added to the if branch.
This ensures consistency in the transformed code.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8708
llvm-svn: 233697
Summary:
Anynoumous namespaces inject a using directive into the AST to import
the names into the containing namespace.
We should not have them in headers, but there is another warning for
that.
Reviewers: djasper
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8443
llvm-svn: 233087
Followup to http://reviews.llvm.org/D8465, which would break a test in
clang-tidy. clang-tidy previously assumes that source locations of
defaulted/deleted members are (incorrectly) not including the '= ...' part.
Differential Revision: http://reviews.llvm.org/D8466
llvm-svn: 233032
Summary: The relevant style rule is going to be removed, thus the check is no longer needed in the Google module. Leaving the check in readability/ in case someone needs it.
Reviewers: djasper
Reviewed By: djasper
Subscribers: curdeius, cfe-commits
Differential Revision: http://reviews.llvm.org/D8261
llvm-svn: 232431
The misc-static-assert check will not warn on assert(false), assert(False),
assert(FALSE); where false / False / FALSE are macros expanding to the false or
0 literals.
Also added corresponding test cases.
http://reviews.llvm.org/D8328
Patch by Szabolcs Sipos!
llvm-svn: 232306
The patch was generated using this command:
$ clang-tidy/tool/run-clang-tidy.py -header-filter=.*clang-tidy.* -fix \
-checks=-*,llvm-header-guard clang-tidy.*
$ svn revert --recursive clangt-tidy/llvm/
(to revert a few buggy fixes)
llvm-svn: 231669
Classes are named WhateverCheck, files are WhateverCheck.cpp and`
WhateverCheck.h`
http://reviews.llvm.org/D8144
Patch by Richard Thomson!
llvm-svn: 231650
Classes are named WhateverCheck, files are named WhateverCheck.cpp and
WhateverCheck.h.
http://reviews.llvm.org/D8145
Patch by Richard Thomson!
llvm-svn: 231648
Summary:
Replace unrecognized namespace ending comments. This will help in particular when a namespace ending comment is mistyped or doesn't fit the regexp for other reason, e.g.:
namespace a {
namespace b {
namespace {
} // anoynmous namespace
} // b
} // namesapce a
Reviewers: djasper
Reviewed By: djasper
Subscribers: curdeius, cfe-commits
Differential Revision: http://reviews.llvm.org/D8078
llvm-svn: 231369
clang-tidy checks are organized into modules. This refactoring moves the llvm
module checks to clang::tidy::llvm
http://reviews.llvm.org/D7995
Patch by Richard Thomson!
llvm-svn: 230952
clang-tidy checks are organized into modules. This refactoring moves the misc
module checks into the namespace clang::tidy::misc
http://reviews.llvm.org/D7996
Patch by Richard Thomson!
llvm-svn: 230950
clang-tidy checks are organized into modules. This refactoring moves the
readability module checks into the namespace clang::tidy::readability
http://reviews.llvm.org/D7997
Patch by Richard Thomson!
llvm-svn: 230946
This patch contains two assert related checkers. These checkers are the part of
those that is being open sourced by Ericsson
(http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-December/040520.html).
The checkers:
AssertSideEffect:
/// \brief Finds \c assert() with side effect.
///
/// The conition of \c assert() is evaluated only in debug builds so a condition
/// with side effect can cause different behaviour in debug / relesase builds.
StaticAssert:
/// \brief Replaces \c assert() with \c static_assert() if the condition is
/// evaluatable at compile time.
///
/// The condition of \c static_assert() is evaluated at compile time which is
/// safer and more efficient.
http://reviews.llvm.org/D7375
Patch by Szabolcs Sipos!
llvm-svn: 230943
* Better error message when more than one of 'virtual', 'override' and 'final'
is present ("X is/are redundant since the function is already declared Y").
* Convert the messages to the style used in Clang diagnostics: lower case
initial letter, no trailing period.
* Don't run the check for files compiled in pre-C++11 mode
(http://llvm.org/PR22638).
llvm-svn: 230765