Summary:
Now, it detects that several kinds of usages are can't modify the elements. Examples:
-When an usage is a call to a const member function or operator of the element.
-If the element is used as an argument to a function or constructor that takes a const-reference or a value.
-LValue to RValue conversion, if the element is a fundamental type (which allows the use of most of the builtin operators).
Reviewers: klimek
Subscribers: cfe-commits, alexfh
Differential Revision: http://reviews.llvm.org/D14198
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251808 91177308-0d34-0410-b5e6-96231b3b80d8
Summary: The check was assuming that a definition of a function always has a body, but a declaration that explicitly defaults or deletes a function is a definition too.
Reviewers: alexfh
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D14238
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251807 91177308-0d34-0410-b5e6-96231b3b80d8
Summary: When traversing the parent map, the check assumed that all the nodes would be either Stmt or Decl. After r251101, this is no longer true: there can be TypeLoc and NestedNameSpecifierLoc nodes.
Reviewers: alexfh
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D14229
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251803 91177308-0d34-0410-b5e6-96231b3b80d8
Summary:
When applying this check to the unit tests, it would hit an assertion:
llvm/tools/clang/lib/Lex/Lexer.cpp:1056: clang::SourceLocation clang::Lexer::getSourceLocation(const char*, unsigned int) const: Assertion `PP && "This doesn't work on raw lexers"' failed.
Reviewers: klimek, LegalizeAdulthood, alexfh
Subscribers: cfe-commits, alexfh
Differential Revision: http://reviews.llvm.org/D14204
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251792 91177308-0d34-0410-b5e6-96231b3b80d8
Summary: If the size of the type is above a certain bound, we'll take a const reference. This bound can be set as an option. For now, the default value is 16 bytes.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D14176
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251694 91177308-0d34-0410-b5e6-96231b3b80d8
This check for clang-tidy looks for function with zero arguments declared as (void) and removes the unnecessary void token.
int foo(void);
becomes
int foo();
The check performs no formatting of the surrounding context but uses the lexer to look for the token sequence "(", "void", ")" in the prototype text. If this sequence of tokens is found, a removal is issued for the void token only.
Patch by Richard Thomson!
(+fixed tests, moved the check to the modernize module)
Differential revision: http://reviews.llvm.org/D7639
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251475 91177308-0d34-0410-b5e6-96231b3b80d8
I totally forgot that char can be defined as unsigned on some platforms.
Now I made explicit mention of signed type where necessary in tests.
Also fixed '//RUN: ' header of cxx98 test to correct format.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251244 91177308-0d34-0410-b5e6-96231b3b80d8
Summary:
This is another check that I ported to clang-tidy from colobot-lint tool.
As previously discussed on cfe-dev mailing list, this is one of those
checks that I think is general and useful enough for contribution to
clang-tidy.
This patch contains implementation of check taken from colobot-lint, but
it is extended a great deal, including FixIt hints for automated
refactoring, exhaustive testcases, and user documentation.
Reviewers: sbenza, aaron.ballman, alexfh
Subscribers: Eugene.Zelenko
Differential Revision: http://reviews.llvm.org/D13635
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251235 91177308-0d34-0410-b5e6-96231b3b80d8
With this, site specific lit configs can inject parameters into the
test scripts if they need site specific parameters.
Next up: enable check_clang_tidy to take a resource dir to enable
non-standard locations for builtin includes.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@251010 91177308-0d34-0410-b5e6-96231b3b80d8
Summary:
Add a check that replaces empty bodies of special member functions with '= default;'.
For now, it is only implemented for the default constructor and the destructor, which are the easier cases.
The copy-constructor and the copy-assignment operator cases will be implemented later.
I applied this check to the llvm code base and found 627 warnings (385 in llvm, 9 in compiler-rt, 220 in clang and 13 in clang-tools-extra).
Applying the fixes didn't break any build or test, it only caused a -Wpedantic warning in lib/Target/Mips/MipsOptionRecord.h:33 becaused it replaced
virtual ~MipsOptionRecord(){}; to virtual ~MipsOptionRecord()= default;;
Reviewers: klimek
Subscribers: george.burgess.iv, Eugene.Zelenko, alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D13871
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@250897 91177308-0d34-0410-b5e6-96231b3b80d8
Summary: Add the second template argument to the unique_ptr mock, and update the matcher so that it only matches against cases where the second argument is the default.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D13433
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@249305 91177308-0d34-0410-b5e6-96231b3b80d8
Summary: Now that we prioritize copying trivial types over using const-references where possible, I found some cases where, after the transformation, the loop was using the address of the local copy instead of the original object.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D13431
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@249300 91177308-0d34-0410-b5e6-96231b3b80d8
Summary:
https://llvm.org/bugs/show_bug.cgi?id=24960
modernize-use-nullptr would hit an assertion in some cases involving macros and initializer lists, due to finding a node with more than one parent (the two forms of the initializer list).
However, this doesn't mean that the replacement is incorrect, so instead of just rejecting this case I tried to find a way to make it work. Looking at the semantic form of the InitListExpr made sense to me (looking at both forms results in false negatives) but I am not sure of the things that we can miss by skipping the syntactic form.
Reviewers: klimek
Subscribers: cfe-commits, alexfh
Differential Revision: http://reviews.llvm.org/D13246
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@249291 91177308-0d34-0410-b5e6-96231b3b80d8
This diff requires http://reviews.llvm.org/D13079 to be applied first. I wasn't sure about how to make patch series in Phabricator, and I wanted to keep the two separate for clarity.
It looks like that most cases can be supported with this patch. I'm not totally sure about the actual coverage though. I think that the matchers are very generic, but I'm still not totally fluent with the AST.
Patch by Beren Minor!
Differential revision: http://reviews.llvm.org/D13081
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@248996 91177308-0d34-0410-b5e6-96231b3b80d8
Summary: create a check that replaces 'std::unique_ptr<type>(new type(args...))' with 'std::make_unique<type>(args...)'. It was on the list of "Ideas for new Tools". It needs to be tested more carefully, but first I wanted to know if you think it is worth the effort.
Reviewers: klimek
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D13166
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@248785 91177308-0d34-0410-b5e6-96231b3b80d8
This is to level the ground a little bit, in preparation for the changes in http://reviews.llvm.org/D13081.
Code factorization replaces all insertions to NamingCheckFailures map with a unique addUsage function that does the job.
There is also no more difference between the declaration and the references to a given identifier, both cases are treated as ranges in the Usage vector. There is also a check to avoid duplicated ranges to be inserted, which sometimes triggered erroneous replacements.
References can now also be added before the declaration of the identifier is actually found; this looks to be the case for example when a templated class uses its parameters to specialize its templated base class.
Patch by Beren Minor!
Differential revision: http://reviews.llvm.org/D13079
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@248700 91177308-0d34-0410-b5e6-96231b3b80d8
Previously, we would rewrite:
void f(const vector<int> &v) {
for (size_t i = 0; i < v.size(); ++i) {
to
for (const auto &elem : v) {
Now we rewrite it to:
for (auto elem : v) {
(and similarly for iterator based loops).
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@248438 91177308-0d34-0410-b5e6-96231b3b80d8
Previously we would use a non-const loop variable in the range-based
loop for:
void f(const std::vector<int> &v) {
for (size_t i = 0; i < v.size(); ++i) {
Now we use const auto&.
Note that we'll also want to use a copy at least for simple types.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@248418 91177308-0d34-0410-b5e6-96231b3b80d8
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
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@247399 91177308-0d34-0410-b5e6-96231b3b80d8
For targeting LLP64, like Windows x86, size_t is not unsigned long.
tools/clang/tools/extra/test/clang-tidy/Output/misc-sizeof-container.cpp.tmp.cpp:33:12: error: target of using declaration conflicts with declaration already in scope [clang-diagnostic-error]
using std::size_t;
^
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@247394 91177308-0d34-0410-b5e6-96231b3b80d8
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
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@247297 91177308-0d34-0410-b5e6-96231b3b80d8
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!
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@247261 91177308-0d34-0410-b5e6-96231b3b80d8
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
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@246989 91177308-0d34-0410-b5e6-96231b3b80d8
Summary:
Add check_clang_tidy.py script that is functionally identical to the
check_clang_tidy.py, but should also be functional on windows.
I've verified that the script works on linux. Would be nice if folks using
Windows could test the patch before I break windows bots ;)
Reviewers: chapuni, aaron.ballman
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D12180
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@245583 91177308-0d34-0410-b5e6-96231b3b80d8
FIXME: "-I %S/Inputs/file-filter/system/.." must be redundant.
On Win32, file-filter/system\system-header1.h precedes file-filter\header*.h due to code order between '/' and '\\'.
We should remove such a tweak to introduce the *right* path canonicalization.
Posix:
file-filter/header*.h
file-filter/system/system-header1.h
Win32:
file-filter/system\system-header1.h
file-filter\header*.h
Win32, tweaked:
file-filter/system/..\header*.h
file-filter/system\system-header1.h
It had been disabled since r220837.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@245566 91177308-0d34-0410-b5e6-96231b3b80d8
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.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@245511 91177308-0d34-0410-b5e6-96231b3b80d8
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!
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@245429 91177308-0d34-0410-b5e6-96231b3b80d8
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
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@245401 91177308-0d34-0410-b5e6-96231b3b80d8
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.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@243267 91177308-0d34-0410-b5e6-96231b3b80d8
Note, clang-tidy tests wouldn't run on Windows hosts since they are disabled with REQUIRES:shell.
The failure would be raised with cross building.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@242984 91177308-0d34-0410-b5e6-96231b3b80d8
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!
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@242912 91177308-0d34-0410-b5e6-96231b3b80d8
to determine files that have comnpilation or dependency problems.
A new -display-file-lists option use this to display lists of good files
(no compile errors), problem files, and a combined list with
problem files preceded by a '#'. The problem files list can be
used in the module map generation assistant mode to exclude
problem files. The combined files list can be used during module
map development. See added docs.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@241880 91177308-0d34-0410-b5e6-96231b3b80d8
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
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@241245 91177308-0d34-0410-b5e6-96231b3b80d8
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!
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@241155 91177308-0d34-0410-b5e6-96231b3b80d8
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).
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@237905 91177308-0d34-0410-b5e6-96231b3b80d8
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!
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@237541 91177308-0d34-0410-b5e6-96231b3b80d8
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.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@236812 91177308-0d34-0410-b5e6-96231b3b80d8
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!
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@234626 91177308-0d34-0410-b5e6-96231b3b80d8
Use "constructors that are callable with a single argument" instead of
"single-argument constructors" when referring to constructors using default
arguments or parameter packs.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@233702 91177308-0d34-0410-b5e6-96231b3b80d8
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
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@232431 91177308-0d34-0410-b5e6-96231b3b80d8
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!
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@232306 91177308-0d34-0410-b5e6-96231b3b80d8
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!
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@230943 91177308-0d34-0410-b5e6-96231b3b80d8
* 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).
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@230765 91177308-0d34-0410-b5e6-96231b3b80d8
Algorithms like remove() does not actually remove any element from the
container but returns an iterator to the first redundant element at the end
of the container. These redundant elements must be removed using the
erase() method. This check warns when not all of the elements will be
removed due to using an inappropriate overload.
Reviewer: alexfh
Differential Revision: http://reviews.llvm.org/D7496
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@228679 91177308-0d34-0410-b5e6-96231b3b80d8
Summary:
Associative containers implements some of the algorithms as methods which
should be preferred to the algorithms in the algorithm header. The methods
can take advantage of the order of the elements.
Reviewers: alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D7246
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@228505 91177308-0d34-0410-b5e6-96231b3b80d8
Summary:
This makes clang-tidy merge the default set of checks with the one
provided in the configuration file instead of just using the checks from the
config file. This adds a way to modify the default set of checks while the
previous behavior required to always define the set of checks completely.
Reviewers: djasper
Reviewed By: djasper
Subscribers: curdeius, cfe-commits
Differential Revision: http://reviews.llvm.org/D7434
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@228298 91177308-0d34-0410-b5e6-96231b3b80d8