Commit Graph

857 Commits

Author SHA1 Message Date
Alexander Kornienko 5ae76e09ad [clang-tidy] readability-identifier-naming - Support for Type Aliases
Summary: Added support for Type Alias declarations.

Reviewers: alexfh

Subscribers: cfe-commits

Patch by James Reynolds!

Differential Revision: http://reviews.llvm.org/D20856

llvm-svn: 271992
2016-06-07 09:11:19 +00:00
Haojian Wu ba992cf3de [clang-tidy] Ignore the deleted function in misc-definitions-in-headers.
Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D21059

llvm-svn: 271991
2016-06-07 08:55:38 +00:00
Miklos Vajna b54a26d19d clang-rename: implement renaming of classes inside static_cast
"Derived" in static_cast<Derived&>(...) wasn't renamed, nor in its
pointer equivalent.

Reviewers: klimek

Differential Revision: http://reviews.llvm.org/D21012

llvm-svn: 271933
2016-06-06 19:40:12 +00:00
Alexander Kornienko c0308c451b [clang-tidy] modernize-use-auto: don't remove stars by default
Summary:
By default, modernize-use-auto check will retain stars when replacing an explicit type with `auto`: `MyType *t = new MyType;` will be changed to `auto *t = new MyType;`, thus resulting in more consistency with the recommendations to use `auto *` for iterating over pointers in range-based for loops: http://llvm.org/docs/CodingStandards.html#beware-unnecessary-copies-with-auto

The new  `RemoveStars` option allows to revert to the old behavior: with the new option turned on the check will change `MyType *t = new MyType;` to `auto t = new MyType;`.

Reviewers: aaron.ballman, sbenza

Subscribers: Eugene.Zelenko, cfe-commits

Differential Revision: http://reviews.llvm.org/D20917

llvm-svn: 271739
2016-06-03 21:22:58 +00:00
Benjamin Kramer b53452b2b1 [include-fixer] Be smarter about inserting symbols for a prefix.
If prefix search finds something where nothing can be nested under (e.g.
a variable or macro) don't add it to the result.

This is for cases like:
header.h:
  extern int a;

file.cc:
namespace a {
  SOME_MACRO
}

We will look up a::SOME_MACRO, which doesn't have any results. Then we
look up 'a' and find something before we ever look up just 'SOME_MACRO'.
With some basic filtering we can avoid this case.

Differential Revision: http://reviews.llvm.org/D20960

llvm-svn: 271671
2016-06-03 14:07:38 +00:00
Haojian Wu d80c7c4808 [clang-tidy] Ignore function context in misc-unused-using-decls.
Summary: Make the check's behavior more correct when handling using-decls in multiple scopes.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20909

llvm-svn: 271632
2016-06-03 08:05:11 +00:00
Miklos Vajna 617409f0c0 clang-rename: fix renaming heap allocations
The check failed, 'Cla *C = new Cla();' was renamed to 'D *C = new Cla();'.

Reviewers: klimek

Differential Revision: http://reviews.llvm.org/D20635

llvm-svn: 271572
2016-06-02 20:00:22 +00:00
Samuel Benzaquen aa05ae91fb Fix uninitialized memory access when the token 'const' is not present in
the program.

If the token is not there, we still warn but we don't try to give a
fixit hint.

llvm-svn: 271426
2016-06-01 20:37:23 +00:00
Haojian Wu 17a54e3618 [include-fixer] Use YAML format in -output-headers and -insert-header mode.
Summary:
And some improvements:
* Show better error messages on unfound symbols.
* Fix a typo.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20827

llvm-svn: 271382
2016-06-01 11:43:10 +00:00
Benjamin Kramer 658d28014b [include-fixer] Rank symbols based on the number of occurrences we found while merging.
This sorts based on the popularity of the header, not the symbol. If
there are mutliple matching symbols in one header we take the maximum
popularity for that header and deduplicate. If we know nothing we sort
lexicographically based on the header path.

Differential Revision: http://reviews.llvm.org/D20814

llvm-svn: 271283
2016-05-31 14:33:28 +00:00
Benjamin Kramer 03016b85b6 [find-all-symbols] Add a test to make sure merging actually works.
llvm-svn: 271270
2016-05-31 12:12:19 +00:00
Eric Liu c893070ff1 [include-fixer] collect the number of times a symbols is found in an indexing run and use it for symbols popularity ranking.
Summary:
[include-fixer] collect the number of times a symbols is found in an
indexing run and use it for symbols popularity ranking.

Reviewers: bkramer

Subscribers: cfe-commits, hokein, djasper

Differential Revision: http://reviews.llvm.org/D20804

llvm-svn: 271268
2016-05-31 12:01:48 +00:00
Haojian Wu 11e9bd2450 [include-fixer] Create a mode in vim integration to show multiple potential headers.
Summary:
Some changes in the patch:

* Add two commandline flags in clang-include-fixer.
* Introduce a IncludeFixerContext for the queried symbol.
* Pull out CreateReplacementsForHeader.

Reviewers: bkramer

Subscribers: klimek, cfe-commits, ioeric

Differential Revision: http://reviews.llvm.org/D20621

llvm-svn: 271258
2016-05-31 09:31:51 +00:00
Felix Berger 98e4019a58 [clang-tidy] UnnecessaryCopyInitialization - Extend to trigger on non-const "this" object argument if it is not modified.
Summary:

Also trigger the check in the following case:

void foo() {
  ExpensiveToCopy Obj;
  const auto UnnecessaryCopy = Obj.constReference();
  Obj.onlyUsedAsConst();
}

i.e. when the object the method is called on is not const but is never
modified.

Reviewers: alexfh, fowles

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20010

llvm-svn: 271239
2016-05-31 00:25:57 +00:00
Haojian Wu 3b9f4cf462 Fix a wrong check in misc-unused-using-decls
Summary:
We should check whether a UsingDecl is defined in macros or in class
definition, not TargetDecls of the UsingDecl.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20666

llvm-svn: 271199
2016-05-30 07:42:22 +00:00
NAKAMURA Takumi 201c955fbc clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp: Tweak for r270775.
llvm-svn: 270841
2016-05-26 11:20:54 +00:00
Benjamin Kramer c85e14e0d6 [clang-tidy] Fix typo in test file name.
polo

llvm-svn: 270682
2016-05-25 09:44:35 +00:00
Miklos Vajna 10e25748b0 clang-rename: fix renaming non-members variables when referenced as macro arguments
The second check failed, FOO(C::X) wasn't renamed to FOO(C::Y).

Reviewers: klimek

Differential Revision: http://reviews.llvm.org/D20537

llvm-svn: 270599
2016-05-24 19:08:53 +00:00
Benjamin Kramer e78ace55df [clang-tidy] Don't rely on <array> being available.
The STL isn't necessarily around when running tests. Make our own fake
std::array to test this.

llvm-svn: 270581
2016-05-24 16:54:26 +00:00
Mads Ravn ef88dc8fe4 [clang-tidy] modernize-pass-by-value bugfix. Reverting lit-style test
Adding to revision 270567. The lit-style test was wrong. This is being fixed by this commit.

This is the bug on bugzilla: https://llvm.org/bugs/show_bug.cgi?id=27731

This is the code review on phabricator: http://reviews.llvm.org/D20365

llvm-svn: 270575
2016-05-24 16:09:24 +00:00
Mads Ravn 28cc243930 [clang-tidy] modernize-pass-by-value bugfix. Reverting lit-style test
Adding to revision 270565. The lit-style test was wrong. This is being fixed by this commit.

This is the bug on bugzilla: https://llvm.org/bugs/show_bug.cgi?id=27731

This is the code review on phabricator: http://reviews.llvm.org/D20365

llvm-svn: 270567
2016-05-24 15:13:44 +00:00
Mads Ravn 7175c2ce4d [clang-tidy] modernize-pass-by-value bugfix
Modified the clang-tidy PassByValue check. It now stops adding std::move to type which is trivially copyable because that caused the clang-tidy MoveConstArg to complain and revert, thus creating a cycle.

I have also added a lit-style test to verify the bugfix.

This is the bug on bugzilla: https://llvm.org/bugs/show_bug.cgi?id=27731

This is the code review on phabricator: http://reviews.llvm.org/D20365

llvm-svn: 270565
2016-05-24 15:00:16 +00:00
Mads Ravn 86d5f8ad4c Commiting for http://reviews.llvm.org/D20365
llvm-svn: 270473
2016-05-23 18:27:05 +00:00
Mads Ravn dfa3b3d3ee Commiting for http://reviews.llvm.org/D20365
llvm-svn: 270472
2016-05-23 18:15:40 +00:00
Mads Ravn d01743a3f7 Commiting for http://reviews.llvm.org/D20365
llvm-svn: 270470
2016-05-23 18:06:29 +00:00
Miklos Vajna ed28d41b1a clang-rename: fix renaming members when referenced as macro arguments
The second check failed, FOO(C.X) wasn't renamed to FOO(C.Y).

Reviewers: klimek

Differential Revision: http://reviews.llvm.org/D20446

llvm-svn: 270204
2016-05-20 11:43:59 +00:00
Haojian Wu 1cea6e5531 [clang-tidy] Handle using-decls with more than one shadow decl.
Reviewers: alexfh

Subscribers: cfe-commits, djasper

Differential Revision: http://reviews.llvm.org/D20429

llvm-svn: 270191
2016-05-20 08:34:32 +00:00
Miklos Vajna 5a6d2985d7 clang-rename: handle non-inline ctor definitions when renaming classes
The result of the test was C::D(), not D::D().

Reviewers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D20356

llvm-svn: 269952
2016-05-18 16:12:48 +00:00
Benjamin Kramer 6b5160a369 [include-fixer] Don't insert #includes if a fatal error occurred.
This typically happens when the user didn't setup include paths correctly
and the fixer starts adding garbage includes. Avoid that. Disable the error
limit though, as we might hit that easily with missing includes and still
want to fix those cases.

llvm-svn: 269923
2016-05-18 13:32:38 +00:00
Haojian Wu 4405d5b2cc [clang-tidy] Fix misc-unused-using-decls test failure in windows
buildbot.

llvm-svn: 269918
2016-05-18 13:07:13 +00:00
Haojian Wu 47ea5424d2 [clang-tidy] Fix a template function false positive in misc-unused-using-decls check.
Summary: Ignore warning uninstantiated template function usages.

Reviewers: djasper, alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20326

llvm-svn: 269906
2016-05-18 11:49:34 +00:00
Vedant Kumar 5119923cdd [clang-tidy] Skip misc-macro-parentheses for namespaces (Fix PR27400)
If a use of a macro argument is preceded by the `namespace` keyword, do
not warn that the use should be wrapped in parentheses.

Patch by Mads Ravn!

llvm-svn: 269786
2016-05-17 17:26:02 +00:00
Felix Berger 9435f54167 [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.
Reviewers: alexfh, sbenza

Subscribers: etienneb, aaron.ballman, cfe-commits

Differential Revision: http://reviews.llvm.org/D20170

llvm-svn: 269581
2016-05-14 22:43:50 +00:00
Felix Berger 6d3d746ff5 [clang-tidy] - PerformanceUnnecesaryCopyInitialization - only trigger for decl stmts with single VarDecl.
Summary: This fixes bug: https://llvm.org/bugs/show_bug.cgi?id=27325

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19865

llvm-svn: 269389
2016-05-13 02:47:56 +00:00
Jonathan Coe a30c69c9e4 [clang-tidy] Adds modernize-avoid-bind check
Summary:
This patch adds a check that replaces std::bind with a lambda.

Not yet working for member functions.

Reviewers: aaron.ballman, alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D16962

llvm-svn: 269341
2016-05-12 20:06:04 +00:00
Haojian Wu 7a4d510ccb [clang-tidy] Ignore using-declarations defined in marcro in misc-unused-using-decls checks.
Reviewers: djasper

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20197

llvm-svn: 269278
2016-05-12 10:00:49 +00:00
Etienne Bergeron c87599f480 [clang-tidy] Improve misc-redundant-expression and decrease false-positive
Summary:
This patch is adding support for conditional expression and overloaded operators.

To decrease false-positive, this patch is adding a list of banned macro names that
has multiple variant with same integer value.

Also fixed support for template instantiation and added an unittest.

Reviewers: alexfh

Subscribers: klimek, Sarcasm, cfe-commits

Differential Revision: http://reviews.llvm.org/D19703

llvm-svn: 269275
2016-05-12 04:32:47 +00:00
Eugene Zelenko 1592d76d73 [Clang-tidy] modernize-use-bool-literals: documentation style.
Fix readability-redundant-control-flow warnings in regression test.

llvm-svn: 269229
2016-05-11 20:31:50 +00:00
Etienne Bergeron 8311c446fc [clang-tidy] Refactoring of FixHintUtils
Summary:
Refactor some checkers to use the tooling re-writing API.
see: http://reviews.llvm.org/D19941

Reviewers: klimek, alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19807

llvm-svn: 269210
2016-05-11 17:38:22 +00:00
Etienne Bergeron e646a833ab [clang-tidy] Add FixIt for swapping arguments in string-constructor-checker.
Summary:
Arguments can be swapped using fixit when they are not in macros.
This is the same implementation than SwappedArguments. Some code 
got lifted to be reused.

Others checks are not safe to be fixed as they tend to be bugs or errors.
It is better to let the user manually review them.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19547

llvm-svn: 269208
2016-05-11 17:32:12 +00:00
Haojian Wu 2d07ed4530 [include-fixer] Add lit-test for relative include path.
Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20159

llvm-svn: 269177
2016-05-11 12:30:45 +00:00
Jakub Staron f7df72694a [clang-tidy] Adds modernize-use-bool-literals check.
Review link: http://reviews.llvm.org/D18745

llvm-svn: 269171
2016-05-11 11:33:16 +00:00
Miklos Vajna 6477682c98 clang-rename: fix renaming of field with implicit initializers
The last check failed as Cla::Cla() was rewritten to Cla::hector().

Reviewers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D20150

llvm-svn: 269161
2016-05-11 08:08:07 +00:00
Benjamin Kramer 8fd85a5788 [include-fixer] Default to YAML db, it's much more useful than the fixed dummy db.
llvm-svn: 269043
2016-05-10 11:35:47 +00:00
Haojian Wu bdb54eb457 Fixed cppcoreguidelines-pro-type-member-init when checking records with indirect fields
Summary:
Fixed a crash in cppcoreguidelines-pro-type-member-init when checking record types with indirect fields pre-C++11.
Fixed handling of indirect fields so they are properly checked and suggested fixes are proposed.

Patch by Michael Miller!

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19993

llvm-svn: 269024
2016-05-10 07:42:19 +00:00
Benjamin Kramer b6aed5f441 [include-fixer] Autodetect yaml databases in parent directories.
This looks for find_all_symbols_db.yaml in all parent directories of the
source file (like we do for compile_commands.json) so we don't have to
pass the path manually.

Differential Revision: http://reviews.llvm.org/D20066

llvm-svn: 268920
2016-05-09 14:14:55 +00:00
Haojian Wu 1172668682 [clang-tidy] new google-default-arguments check
Summary:
To check the google style guide rule here:
https://google.github.io/styleguide/cppguide.html#Default_Arguments

Patch by Clement Courbet!

Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19534

llvm-svn: 268919
2016-05-09 13:43:58 +00:00
Haojian Wu 769eb0d5d5 Support variables and functions types in misc-unused-using-decls.
Summary: Fix PR27429.

Reviewers: djasper

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20018

llvm-svn: 268917
2016-05-09 13:37:12 +00:00
Miklos Vajna 0f450b6b9a clang-rename tests: move the run lines to the top of the test files
Summary: To be consistent with the other tests.

Reviewers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D20059

llvm-svn: 268897
2016-05-09 08:47:18 +00:00
Miklos Vajna 65f088f528 clang-rename: when renaming a field, rename initializers of that field as well
Summary: The second check failed, the initializer wasn't renamed.

Reviewers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D19957

llvm-svn: 268857
2016-05-07 14:32:59 +00:00
Alexander Kornienko 1ccc219125 [clang-tidy] Improve -warnings-as-errors tests.
llvm-svn: 268579
2016-05-05 00:09:29 +00:00
Alexander Kornienko dbefbdb6d1 [clang-tidy] Apply NOLINT filtering to Clang warnings.
llvm-svn: 268555
2016-05-04 21:18:31 +00:00
Gabor Horvath 30e962a158 [clang-tidy] Remove STL dependency from a test.
llvm-svn: 268494
2016-05-04 12:17:55 +00:00
Gabor Horvath 112d1e80c0 [clang-tidy] New: checker misc-unconventional-assign-operator replacing misc-assign-operator-signature
Summary: Finds return statements in assign operator bodies where the return value is different from '*this'. Only assignment operators with correct return value Class& are checked.

Reviewers: aaron.ballman, alexfh, sbenza

Subscribers: o.gyorgy, baloghadamsoftware, LegalizeAdulthood, aaron.ballman, Eugene.Zelenko, xazax.hun, cfe-commits

Differential Revision: http://reviews.llvm.org/D18265

llvm-svn: 268492
2016-05-04 12:02:22 +00:00
Manuel Klimek 13e2c1a709 When renaming a class, ename pointers to that class as well.
Patch by Miklos Vajna.

llvm-svn: 268484
2016-05-04 09:45:44 +00:00
Felix Berger 99a0dddb3a [clang-tidy] MoveConstructorInitCheck - Add parameter name to check message.
Reviewers: alexfh

Subscribers: aaron.ballman, cfe-commits

Differential Revision: http://reviews.llvm.org/D19849

llvm-svn: 268461
2016-05-03 23:07:44 +00:00
Haojian Wu 2e1ebca2c4 Fix cppcoreguidelines-pro-type-member-init failure test on Windows.
llvm-svn: 268374
2016-05-03 11:19:46 +00:00
Haojian Wu b5cac80c77 Fix a crash in cppcoreguidelines-pro-type-member-init when checking a class that initializes itself as a base
Summary: Fix a crash when a record type initializes itself in its own base class initializer list.

Patch by Michael Miller!

Reviewers: alexfh, aaron.ballman, hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19802

llvm-svn: 268369
2016-05-03 08:11:47 +00:00
Felix Berger b6947a5847 [clang-tidy] ProTypeMemberInitCheck - check that field decls do not have in-class initializer.
Reviewers: alexfh, JVApen, aaron.ballman

Subscribers: flx, aaron.ballman, cfe-commits

Differential Revision: http://reviews.llvm.org/D18300

llvm-svn: 268352
2016-05-03 01:41:19 +00:00
Piotr Padlewski ce18ade406 [clang-tidy] Add modernize-make-shared check
Because modernize-make-shared do almost the same job as
modernize-make-unique, I refactored common code to MakeSmartPtrCheck.

http://reviews.llvm.org/D19183

llvm-svn: 268253
2016-05-02 16:56:39 +00:00
Aaron Ballman d744e63d90 Add a clang-tidy check that flags string-to-number conversion functions that have insufficient error checking, suggesting a better alternative.
This check corresponds to: https://www.securecoding.cert.org/confluence/display/c/ERR34-C.+Detect+errors+when+converting+a+string+to+a+number

llvm-svn: 268100
2016-04-29 20:56:48 +00:00
Piotr Padlewski 5625f65667 Add boost-use-to-string
http://reviews.llvm.org/D18136

llvm-svn: 268079
2016-04-29 17:58:29 +00:00
Haojian Wu d8c12badad [include-fixer] Add Yaml database integration.
Reviewers: bkramer

Subscribers: cfe-commits, klimek, djasper

Differential Revision: http://reviews.llvm.org/D19648

llvm-svn: 268017
2016-04-29 09:23:38 +00:00
Alexander Kornienko fabdbe4732 [clang-tidy] cppcoreguidelines-pro-type-member-init should not complain about static variables
Summary:
Variables with static storage duration are zero-initialized per
[stmt.dcl]p4 and [basic.start.init]p2.

Reviewers: sbenza, aaron.ballman

Subscribers: michael_miller, flx, cfe-commits

Differential Revision: http://reviews.llvm.org/D19672

llvm-svn: 267933
2016-04-28 20:20:01 +00:00
NAKAMURA Takumi f46c273977 clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp: Appease ms targets with -fno-delayed-template-parsing.
llvm-svn: 267828
2016-04-28 00:39:48 +00:00
Haojian Wu 8eb70bc625 Fix explain-check failure test on Windows.
llvm-svn: 267736
2016-04-27 16:39:42 +00:00
Haojian Wu 5b759f82fa Don't search compilation database in explain-check, fixing buildbot test
failure.

llvm-svn: 267731
2016-04-27 16:09:34 +00:00
Benjamin Kramer cf4c6d860a Add missing dependency.
llvm-svn: 267721
2016-04-27 14:32:36 +00:00
Benjamin Kramer f412e9029d Clean up the include fixer 'driver' a bit and make the database configurable.
Also add a test for it. The library is covered by unit tests, the driver
was not.

llvm-svn: 267718
2016-04-27 14:24:32 +00:00
Haojian Wu 68d2b881d2 Remove explain-config testcase that detect hard-coded check.
Remove it for now, we need to better way to figure out how to test it.

llvm-svn: 267711
2016-04-27 13:23:39 +00:00
Haojian Wu 20d4c20bca Fix a crash in cppcoreguidelines-pro-type-member-init when checking a type with a template parameter as a base class.
Summary: Fixed a crash in cppcoreguidelines-pro-type-member-init when encountering a type that uses one of its template parameters as a base when compiling for C++98.

Patch by Michael Miller!

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19539

llvm-svn: 267700
2016-04-27 12:17:04 +00:00
Haojian Wu cd32384539 Don't search compilation database in explain-check test.
Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19583

llvm-svn: 267687
2016-04-27 10:22:31 +00:00
Haojian Wu 12e6b8f929 [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.
Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18694

llvm-svn: 267683
2016-04-27 09:15:01 +00:00
Alexander Kornienko 900cadd3ad [clang-tidy] Now adding correct misc-move-const-arg documentation ;]
+ brushed the code a bit and renamed the test file to match the check name

llvm-svn: 267592
2016-04-26 19:33:49 +00:00
Etienne Bergeron bda187decd [clang-tidy] New checker for redundant expressions.
Summary:
This checker finds redundant expression on both side of a binary operator.

The current implementation provide a function to check whether expressions
are equivalent. This implementation is able to recognize the common
subset encounter in C++ program. Side-effects like "x++" are not considered
to be equivalent.

There are many False Positives related to macros and to floating point
computations (detecting NaN). The checker is ignoring these cases.

Example:
```
    if( !dst || dst->depth != desired_depth ||
        dst->nChannels != desired_num_channels ||
        dst_size.width != src_size.width ||
        dst_size.height != dst_size.height )    <<--- bug
    {
```

Reviewers: alexfh

Subscribers: danielmarjamaki, fahlgren, jordan_rose, zaks.anna, Eugene.Zelenko, cfe-commits

Differential Revision: http://reviews.llvm.org/D19451

llvm-svn: 267574
2016-04-26 17:30:30 +00:00
Etienne Bergeron 1b94f6504b [clang-tidy] Enhance misc-suspicious-string-compare to move down false-positives.
Summary:
The checker was noisy when running over llvm code base.
This patch is impriving the way string-compare functions are matched.

1) By default, do not report !strcmp(...) unless it's activate by the user,
2) Only match suspicious expression over a subset of expression (binary operator),
3) Added matching of macro wrapper used with clang on linux.

See bug: 27465.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19497

llvm-svn: 267570
2016-04-26 16:53:21 +00:00
Alexander Kornienko 6e2f32c561 A clang-tidy check for std:accumulate.
Summary:
For folds (e.g. std::accumulate), check matches between the provided init value and the range's value_type. A typical error is "std::accumulate(begin, end, 0);", where begin and end have float value_type. See the documentation for more examples.

For now we check std::accumulate, std::reduce and std::inner_product.

Reviewers: hokein, alexfh

Subscribers: Prazek, aaron.ballman, cfe-commits, courbet

Patch by Clément Courbet!

Differential Revision: http://reviews.llvm.org/D18442

llvm-svn: 267542
2016-04-26 10:05:45 +00:00
Alexander Kornienko 5142c0d7fa [clang-tidy] Fix misc-macro-repeated-side-effects false positive with stringified arguments
llvm-svn: 267254
2016-04-23 00:00:08 +00:00
Etienne Bergeron 1dbd582387 [clang-tidy] New checker to detect suspicious string constructor.
Summary:
Checker to validate string constructor parameters.

A common mistake is to swap parameter for the fill-constructor.
```
  std::string str('x', 4);
  std::string str('4', x);
```

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19146

llvm-svn: 267011
2016-04-21 17:28:08 +00:00
Etienne Bergeron bae829ede5 [clang-tidy] Add new checker for comparison with runtime string functions.
Summary:
This checker is validating suspicious usage of string compare functions.

Example:
```
  if (strcmp(...))       // Implicitly compare to zero
  if (!strcmp(...))      // Won't warn
  if (strcmp(...) != 0)  // Won't warn
```

This patch was checked over large amount of code.
There is three checks:
  [*] Implicit comparator to zero (coding-style, many warnings found),
  [*] Suspicious implicit cast to non-integral (bugs!?, almost none found),
  [*] Comparison to suspicious constant (bugs!?, found two cases),

Example:
[[https://github.com/kylepjohnson/sigma/blob/master/sigma/native-installers/debian/dependencies/files/opt/sigma/E/HEURISTICS/che_to_precgen.c |
https://github.com/kylepjohnson/sigma/blob/master/sigma/native-installers/debian/dependencies/files/opt/sigma/E/HEURISTICS/che_to_precgen.c]]

```
      else if(strcmp(id, "select") == 0)
      {
         array->array[i].key1 = 25;
      }
      else if(strcmp(id, "sk") == 28)      // BUG!?
      {
         array->array[i].key1 = 20;
      }
```

Reviewers: alexfh

Subscribers: Eugene.Zelenko, cfe-commits

Differential Revision: http://reviews.llvm.org/D18703

llvm-svn: 267009
2016-04-21 17:19:36 +00:00
Alexander Kornienko bfb43b7298 [Clang-tidy] Fix for crash in modernize-raw-string-literal check
Summary:
Clang-tidy modernize-raw-string-literal check crashes on run-time assert while it is evaluating compiler predefined identifiers such as
- __FUNCTION__
- __func__
- __PRETTY_FUNCTION__

Check is asserting because it cannot find opening quote for such string literal. It occurs only on debug build config.
I think that it would be good to prune such cases by crossing off predefined expressions - there is no need to evaluate such matches.

Reviewers: LegalizeAdulthood, alexfh

Subscribers: cfe-commits

Patch by Marek Jenda!

Differential Revision: http://reviews.llvm.org/D19331

llvm-svn: 266992
2016-04-21 14:39:12 +00:00
Daniel Jasper 25e17df663 clang-tidy: [misc-unused-using-decls] Support template types.
This fixes llvm.org/PR27429.

llvm-svn: 266866
2016-04-20 09:48:56 +00:00
Daniel Jasper a204c0ad18 clang-tidy: [misc-unused-using-decls] Always use the canonical decl to
identify things.

This fixes llvm.org/PR27430.

llvm-svn: 266864
2016-04-20 08:58:27 +00:00
Haojian Wu 257914e7c9 Fix a crash in cppcoreguidelines-pro-type-member-init related to missing constructor bodies.
Summary: Fixes a crash in cppcoreguidelines-pro-type-member-init when checking some record types with a constructor without a body. We now check to make sure the constructor has a body before looking for missing members and base initializers.

Patch by Michael Miller!

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19270

llvm-svn: 266862
2016-04-20 08:29:08 +00:00
Daniel Jasper 727fd1aeed Initial version of misc-unused-using-decl check.
llvm-svn: 266735
2016-04-19 13:48:39 +00:00
Gabor Horvath 533c01d9b1 [clang-tidy] readability-container-size-empty fixes
Summary: This patch fixes PR27410 and adds std::basic_string support.

Reviewers: Eugene.Zelenko, hokein

Subscribers: cfe-commits, o.gyorgy

Differential Revision: http://reviews.llvm.org/D19262

llvm-svn: 266734
2016-04-19 13:29:05 +00:00
Alex Denisov 71c8440e55 Replace hardcoded comment at 'lit.site.cfg.in'
At the moment almost every lit.site.cfg.in contains two lines comment:

  ## Autogenerated by LLVM/Clang configuration.
  # Do not edit!

The patch adds variable LIT_SITE_CFG_IN_HEADER, that is replaced from
configure_lit_site_cfg with the note and some useful information.

llvm-svn: 266518
2016-04-16 07:01:42 +00:00
Etienne Bergeron 9cfd8cea6b [clang-tidy] Add more detection rules for redundant c_str calls.
Summary:
The string class contains methods which support receiving either a string literal or a string object.

For example, calls to append can receive either a char* or a string.
```
  string& append (const string& str);
  string& append (const char* s);
```

Which make these cases equivalent, and the .c_str() useless:
```
  std::string s = "123";
  str.append(s);
  str.append(s.c_str());
```

In these cases, removing .c_str()  doesn't provide any size or speed improvement.
It's only a readability issue.

If the string contains embedded NUL characters,  the string literal and the string
object won't produce the same semantic.

Reviewers: alexfh, sbenza

Subscribers: LegalizeAdulthood, aaron.ballman, chapuni, Eugene.Zelenko, cfe-commits

Differential Revision: http://reviews.llvm.org/D18475

llvm-svn: 266463
2016-04-15 18:12:06 +00:00
Etienne Bergeron 1f696b316c [clang-tidy] Add new checker for suspicious sizeof expressions
Summary:
This check is finding suspicious cases of sizeof expression.

Sizeof expression is returning the size (in bytes) of a type or an
expression. Programmers often abuse or misuse this expression.

This checker is adding common set of patterns to detect some
of these bad constructs.


Some examples found by this checker:

R/packages/ifultools/ifultools/src/fra_neig.c
```
        /* free buffer memory */
        (void) mutil_free( dist_buff, sizeof( ctr * sizeof( double ) ) );
        (void) mutil_free( nidx_buff, sizeof( ctr * sizeof( sint32 ) ) );
```


graphviz/v2_20_2/lib/common/utils.c
```
static Dtdisc_t mapDisc = {
    offsetof(item, p),
    sizeof(2 * sizeof(void *)),
    offsetof(item, link),
    (Dtmake_f) newItem,
    (Dtfree_f) freeItem,
    (Dtcompar_f) cmpItem,
    NIL(Dthash_f),
    NIL(Dtmemory_f),
    NIL(Dtevent_f)
};
```


mDNSResponder/mDNSShared/dnsextd.c
```
	context = ( TCPContext* ) malloc( sizeof( TCPContext ) );
	require_action( context, exit, err = mStatus_NoMemoryErr; LogErr( "AcceptTCPConnection", "malloc" ) );
	mDNSPlatformMemZero( context, sizeof( sizeof( TCPContext ) ) );
	context->d		 = self;
```

Reviewers: alexfh

Subscribers: malcolm.parsons, Eugene.Zelenko, cfe-commits

Differential Revision: http://reviews.llvm.org/D19014

llvm-svn: 266451
2016-04-15 16:36:00 +00:00
Etienne Bergeron 3c5be6c9a7 [clang-tidy] Add checker for operations between integrals and pointers
Summary:
This check is finding suspicious operations involving pointers and integral types; which are most likely bugs.

Examples:
subversion/v1_6/subversion/libsvn_subr/utf.c
```
static const char *
fuzzy_escape(const char *src, apr_size_t len, apr_pool_t *pool)
{
  [...]
   while (src_orig < src_end)
    {
      if (! svn_ctype_isascii(*src_orig) || src_orig == '\0')   // Should be *src_orig
        {
```

apache2/v2_2_23/modules/metadata/mod_headers.c
```
static char *parse_format_tag(apr_pool_t *p, format_tag *tag, const char **sa)
{
  [...]
    tag->arg = '\0';   // ERROR: tag->arg has type char*

    /* grab the argument if there is one */
    if (*s == '{') {
        ++s;
        tag->arg = ap_getword(p,&s,'}');
    }
```

Reviewers: alexfh

Subscribers: Eugene.Zelenko, cfe-commits

Differential Revision: http://reviews.llvm.org/D19118

llvm-svn: 266450
2016-04-15 16:31:15 +00:00
Samuel Benzaquen 4fa2d57c6d [clang-tidy] Add check misc-multiple-statement-macro
Summary:
The check detects multi-statement macros that are used in unbraced conditionals.
Only the first statement will be part of the conditionals and the rest will fall
outside of it and executed unconditionally.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18766

llvm-svn: 266369
2016-04-14 21:15:57 +00:00
Aaron Ballman b602ee7d8f Add support for type aliases to modernize-redundant-void-arg.cpp
Patch by Clement Courbet.

llvm-svn: 266358
2016-04-14 19:28:13 +00:00
NAKAMURA Takumi 42b5969862 clang-tools-extra/test/clang-tidy/readability-deleted-default.cpp: Add -fno-ms-compatibility.
llvm-svn: 266265
2016-04-13 23:50:45 +00:00
Alexander Kornienko 855d97e30c Complete support for C++ Core Guidelines Type.6: Always initialize a member variable.
Summary: Added the remaining features needed to satisfy C++ Core Guideline Type.6: Always initialize a member variable to cppcoreguidelines-pro-type-member-init. The check now flags all default-constructed uses of record types without user-provided default constructors that would leave their memory in an undefined state. The check suggests value initializing them instead.

Reviewers: flx, alexfh, aaron.ballman

Subscribers: klimek, aaron.ballman, LegalizeAdulthood, cfe-commits

Patch by Michael Miller!

Differential Revision: http://reviews.llvm.org/D18584

llvm-svn: 266191
2016-04-13 11:35:47 +00:00
Alexander Kornienko 4191b90c75 [clang-tidy] Add a readability-deleted-default clang-tidy check.
Checks if constructors and assignment operators that are marked '= default' are
actually deleted by the compiler.

Patch by Alex Pilkiewicz!

Differential Revision: http://reviews.llvm.org/D18961

llvm-svn: 266190
2016-04-13 11:33:40 +00:00
Matthias Gehre 018c1d4243 [clang-tidy] fix readability-avoid-const-params-in-decls creating invalid code in fix-its
Summary:
The Fix-Its for the added test cases were before:
-void F11(const unsigned int /*version*/);
+void F11(unsigned int int /*version*/);

-void F12(const bool b = true);
+void F12(_Bool true);

Reviewers: fowles, hokein, sbenza, alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18993

llvm-svn: 266044
2016-04-12 05:45:13 +00:00
Alexander Kornienko 477e5d8d31 [clang-tidy] cppcoreguidelines-interfaces-global-init
Summary:
This check flags initializers of globals that access extern objects, and therefore can lead to order-of-initialization problems (this recommandation is part of CPP core guidelines).
Note that this only checks half of the guideline for now (it does not enforce using constexpr functions).

Reviewers: aaron.ballman, alexfh

Subscribers: aaron.ballman, etienneb, Eugene.Zelenko, cfe-commits

Patch by Clement Courbet!

Differential Revision: http://reviews.llvm.org/D18649

llvm-svn: 265774
2016-04-08 09:51:06 +00:00
Etienne Bergeron a5fd19ba1e [clang-tidy] add new checker for string literal with NUL character.
Summary:
This patch adds the support for detecting suspicious string
literals and their //incorrect// usage.

The following example shows a incorrect character escaping leading 
to an embedded NUL character. 
```
  std::string str = "\0x42";   // Should be "\x42".
```

The patch also add detection of truncated literal when a literal
is passed to a string constructor.

Reviewers: hokein, alexfh

Subscribers: LegalizeAdulthood, bcraig, Eugene.Zelenko, bkramer, cfe-commits

Differential Revision: http://reviews.llvm.org/D18783

llvm-svn: 265691
2016-04-07 16:16:36 +00:00
Etienne Bergeron 2c82ebe813 [clang-tidy] fix a crash with -fdelayed-template-parsing in UnnecessaryValueParamCheck.
Summary:
This is the same kind of bug than [[ http://reviews.llvm.org/D18238 | D18238 ]].

Fix crashes caused by deferencing null pointer when declarations parsing may be delayed.
The body of the declarations may be null.

The crashes were observed with a Windows build of clang-tidy and the following command-line.
```
command-line switches: -fms-compatibility-version=19 -fms-compatibility
```

Reviewers: alexfh

Subscribers: kimgr, LegalizeAdulthood, cfe-commits

Differential Revision: http://reviews.llvm.org/D18852

llvm-svn: 265681
2016-04-07 14:58:13 +00:00
Benjamin Kramer a62e223281 [clang-tidy] Remove unnecessary getName() on Decls and Types feeding into a DiagnosticBuilder
Going through a string removes some of the smarts of the diagnosic printer
and makes the code more complicated. This change has some cosmetic impact
on the output but that's mostly minor.

llvm-svn: 265680
2016-04-07 14:55:25 +00:00
Etienne Bergeron f6660dab02 [clang-tidy] Fix FP with readability-redundant-string-init for default arguments
Summary:
Clang-tidy is reporting a warning of redundant string initialisation
on a string parameter initialized with empty string.

See bug: 27087

The reported example is:
```
#include <string>
void fn(std::string a = "");
```

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18829

llvm-svn: 265671
2016-04-07 14:18:53 +00:00
Gabor Horvath 5273f615c4 [clang-tidy] Extension of checker misc-misplaced-widening-cast
Summary:
Existing checker misc-misplaced-widening-cast was extended:
- New use cases: casted expression as lhs or rhs of a logical comparison or function argument
- New types: beside int, long and long long various char types, short and int128 added
- New option to check implicit casts: forgetting a cast is at least as common and as dangerous as misplacing it. This option can be disabled.

This patch depends on AST Matcher patches D17986 and D18243 and also contains fix for checker misc-bool-pointer-implicit-conversion needed because of the fix in the AST Matcher patch.

Reviewers: hokein, alexfh

Subscribers: o.gyorgy, xazax.hun, cfe-commits

Differential Revision: http://reviews.llvm.org/D17987

llvm-svn: 265532
2016-04-06 12:04:51 +00:00
Haojian Wu c253f8b06b [clang-tidy] Add a check to detect static definitions in anonymous namespace.
Summary: Fixes PR26595

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18180

llvm-svn: 265384
2016-04-05 11:42:08 +00:00
Etienne Bergeron 1eec3f01f0 [clang-tidy] Reduce false-positive ratio in misc-suspicious-missing-comma check.
Summary:
This patch is adding detection of common string literal patterns
that should not trigger warnings.

  [*] Add a limit on the number of concatenated token,
  [*] Add support for parenthese sequence of tokens,
  [*] Add detection of valid indentation.

As an example, this code will no longer trigger a warning:
```
const char* Array[] = {
  "first literal"
    "indented literal"
    "indented literal",
  "second literal",
  [...]
```

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18695

llvm-svn: 265303
2016-04-04 15:46:38 +00:00
Alexander Kornienko 09464e63d8 [clang-tidy] fix a couple of modernize-use-override bugs
Fix for __declspec attributes and const=0 without space

This patch is to address 2 problems I found with Clang-tidy:modernize-use-override.

1: missing spaces on pure function decls.

Orig:
void pure() const=0
Problem:
void pure() constoverride =0
Fixed:
void pure() const override =0

2: This is ms-extension specific, but possibly applies to other attribute types. The override is placed before the attribute which doesn’t work well with declspec as this attribute can be inherited or placed before the method identifier.

Orig:
class __declspec(dllexport) X : public Y

{
void p();
};
Problem:
class override __declspec(dllexport) class X : public Y

{
void p();
};
Fixed:
class __declspec(dllexport) class X : public Y

{
void p() override;
};

Patch by Robert Bolter!

Differential Revision: http://reviews.llvm.org/D18396

llvm-svn: 265298
2016-04-04 14:31:36 +00:00
Alexander Kornienko c2822bd3d1 [clang-tidy] Update an example. NFC.
llvm-svn: 265210
2016-04-02 03:44:23 +00:00
Haojian Wu 7d15853c9f [clang-tidy] Don't delete unused parameter in class override method in anonymous namespace.
Summary: Fixes PR26740.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17926

llvm-svn: 265117
2016-04-01 07:57:30 +00:00
Etienne Bergeron 3e4adf1762 [clang-tidy] Add a new checker to detect missing comma in initializer list.
Summary:
This checker is able to detect missing comma in 
an array of string literals.

```
  const char* A[] = {
    "abc",
    "def"   // missing comma (no compiler warnings)
    "ghi",
  };
```

The ratio of false-positive is reduced by restricting the
size of the array considered and the ratio of missing
comma.

To validate the quantity of false positive, the checker
was tried over LLVM and chromium code and detected these
cases:

[[ http://reviews.llvm.org/D18454 | http://reviews.llvm.org/D18454 ]]
[[https://codereview.chromium.org/1807753002/ | https://codereview.chromium.org/1807753002/]]
[[https://codereview.chromium.org/1826193002/ | https://codereview.chromium.org/1826193002/]]
[[https://codereview.chromium.org/1805713002/ | https://codereview.chromium.org/1805713002/]]

Reviewers: alexfh

Subscribers: LegalizeAdulthood, szdominik, xazax.hun, cfe-commits

Differential Revision: http://reviews.llvm.org/D18457

llvm-svn: 265033
2016-03-31 18:12:23 +00:00
Alexander Kornienko e3ae0c6f19 [clang-tidy] readability check for const params in declarations
Summary: Adds a clang-tidy warning for top-level consts in function declarations.

Reviewers: hokein, sbenza, alexfh

Subscribers: cfe-commits

Patch by Matt Kulukundis!

Differential Revision: http://reviews.llvm.org/D18408

llvm-svn: 264856
2016-03-30 11:31:33 +00:00
Samuel Benzaquen b2ccba5257 [clang-tidy] Add check to detect dangling references in value handlers.
Summary:
Add check misc-dangling-handle to detect dangling references in value
handlers like std::experimental::string_view.
It provides a configuration option to specify other handle types that
should also be checked.

Right now it detects:
 - Construction from temporaries.
 - Assignment from temporaries.
 - Return statements from temporaries or locals.
 - Insertion into containers from temporaries.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17811

llvm-svn: 264759
2016-03-29 18:02:26 +00:00
Felix Berger 3c8edde141 [clang-tidy] Add performance check to flag function parameters of expensive to copy types that can be safely converted to const references.
Reviewers: alexfh

Subscribers: fowles, cfe-commits

Differential Revision: http://reviews.llvm.org/D17491

llvm-svn: 264694
2016-03-29 02:42:38 +00:00
Richard Thomson 17d5b81f79 clang-tidy: Fix broken buildbot
VS 2013 does not support char16_t or char32_t

llvm-svn: 264563
2016-03-28 04:15:41 +00:00
Richard Thomson 8930aab886 clang-tidy: Add check modernize-raw-string-literal
llvm-svn: 264539
2016-03-27 16:43:44 +00:00
NAKAMURA Takumi 6517fb4ff9 3rd attempt of fixup with -std=c++11
llvm-svn: 264367
2016-03-25 00:24:35 +00:00
NAKAMURA Takumi 9f7e2d7657 Fixup -- "-target x86_64-unknown -fno-ms-compatibility" didn't work as expected.
llvm-svn: 264365
2016-03-25 00:16:13 +00:00
NAKAMURA Takumi e0451c9378 clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp: Appease MS targets with -fno-ms-compatibility.
FIXME: Add a test with  -fms-compatibility.
llvm-svn: 264362
2016-03-25 00:05:33 +00:00
Etienne Bergeron cb7ce98486 [clang-tidy] Add support for different char-types for the readability-redundant-string-cstr checker.
Summary:
The current checker is able to recognize std::string but does not recognize other string variants.
This patch is adding the support for any string defined with basic_string without considering the
the underlying char type.

The most common variant is: 'std::wstring' based on 'wchar_t'.

There are also other string variants added to the standard: u16string, u32string, etc...

Reviewers: alexfh

Subscribers: mamai, dblaikie, cfe-commits

Differential Revision: http://reviews.llvm.org/D18412

llvm-svn: 264325
2016-03-24 19:42:36 +00:00
Gabor Horvath 4530b52a23 [clang-tidy] misc-assign-operator-signature checker checks return value of all assign operators
The return value of every assign operator should be Type&, not only for copy and move assign operators. 

Patch by Adam Balogh!

Reviewers: hokein, alexfh

Differential Revision: http://reviews.llvm.org/D18264

llvm-svn: 264251
2016-03-24 10:12:08 +00:00
Haojian Wu 6ccb1dd9f0 Add check for unneeded copies of locals
Summary: Extends the UnnecessaryCopyInitialization to detect copies of local variables and parameters that are unneeded.

Patch by Matt Kulukundis!

Reviewers: alexfh, hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18149

llvm-svn: 264146
2016-03-23 09:33:07 +00:00
Etienne Bergeron e409e688a3 [clang-tidy] Fix broken test with redundant string init (msvc).
Summary:
There is a silly bug that got introduced after fixing incorrect paths with this patch:
http://reviews.llvm.org/D18293

The tests was present twice in the file.

Reviewers: alexfh, rnk

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18365

llvm-svn: 264080
2016-03-22 18:21:17 +00:00
Etienne Bergeron 4c3b55cfce [clang-tidy] Fix redundant-string-cstr check with msvc 14 headers.
Summary:
The string constructors are not defined using optional parameters and are not recognize by the checker.

The constructor defined in the MSVC header is defined with 1 parameter. Therefore, patterns are not recognized by the checker.
The current patch add support to accept constructor with only one parameter.

Repro on a Visual Studio 14 installation with the following code:
```
void f1(const std::string &s) {
  f1(s.c_str());
}
```

In the xstring.h header, the constructors are defined this way:
```
basic_string(const _Myt& _Right) [...]
basic_string(const _Myt& _Right, const _Alloc& _Al) [...]
```

The CXXConstructExpr to recognize only contains 1 parameter.
```
CXXConstructExpr 0x3f1a070 <C:\src\llvm\examples\test.cc:6:6, col:14> 'const std::string':'const class std::basic_string<char, struct std::char_traits<char>, class
 std::allocator<char> >' 'void (const char *) __attribute__((thiscall))'
`-CXXMemberCallExpr 0x3f1a008 <col:6, col:14> 'const char *'
  `-MemberExpr 0x3f19fe0 <col:6, col:8> '<bound member function type>' .c_str 0x3cc22f8
    `-DeclRefExpr 0x3f19fc8 <col:6> 'const std::string':'const class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >' lvalue ParmVar 0x3f19c80 's' 'const std::string &'
```

Reviewers: aaron.ballman, alexfh

Subscribers: aemerson

Differential Revision: http://reviews.llvm.org/D18285

llvm-svn: 264075
2016-03-22 18:00:13 +00:00
Etienne Bergeron 6feeb6554e [clang-tidy] Skip reporting of not applicable fixes.
Summary:
Invalid source location are causing clang-tidy to crash when manipulating an invalid file.

Macro definitions on the command line have locations in a virtual buffer and therefore
don't have a corresponding valid FilePath.

A recent patch added path conversion to absolute path. As the FilePath may now be empty,
the result of makeAbsolutePath may incorrectly be the folder WorkingDir.  The crash occurs
in getLocation which is not able to find the appropriate FileEntry (null pointer).

```
          SmallString<128> FixAbsoluteFilePath = Fix.getFilePath();
          Files.makeAbsolutePath(FixAbsoluteFilePath);
          FixLoc = getLocation(FixAbsoluteFilePath, Fix.getOffset());
```

With relative path, the code was not crashing because getLocation was skipping empty path.



Example of code:

```
int main() { return X; }
```

With the given command-line:

```
clang-tidy test.cc --checks=misc-macro-*  --  -DX=0+0
```

Reviewers: alexfh, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Differential Revision: http://reviews.llvm.org/D18262

llvm-svn: 264073
2016-03-22 17:51:27 +00:00
Etienne Bergeron 1329b986d2 [clang-tidy] Fix redundant-string-init check with msvc 14 headers.
Summary:
The string constructors are not defined using optional parameters and are not recognized by the redundant-string-init checker.

The following patch fixes the redundant-string-init checker for the Visual Studio 14 headers file.
The matcher now accept both variant (with 1 and 2 parameters).

Also added new unittests.

Similar issue than: [[ http://reviews.llvm.org/D18285 | review ]]

In the xstring.h header, the constructors are defined this way:
```
basic_string(const _Myt& _Right) [...]
basic_string(const _Myt& _Right, const _Alloc& _Al) [...]
```

Reviewers: alexfh, hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18293

llvm-svn: 264069
2016-03-22 17:39:36 +00:00
Aaron Ballman 4c9c07414e Moving files that were placed in the wrong directory from r264049.
llvm-svn: 264050
2016-03-22 13:44:36 +00:00
John Thompson 1c158c192a Fixed some cases in the modularize assistant mode where header file names didn't translate to valid module names.
llvm-svn: 264001
2016-03-21 23:05:14 +00:00
Samuel Benzaquen bd6a74e1fa [clang-tidy] Fix check broken in rL263822.
Add names missing from rL263822 and add tests to prevent future omissions.

llvm-svn: 263963
2016-03-21 18:00:43 +00:00
Haojian Wu e641cb4807 [clang-tidy] Fix "Name is not a simple identifier" assertion in `modernize-loop-convert` check.
Summary:
Fix assertion failure: "Name is not a simple identifier".

`Decl::GetName` assumes the name should be an identifier. When the check
processes the function calling statement with speciail key name like
'it.operator->()', it will trigger the assert in `GetName`.

Rather than using `Decl::GetName`, we use `getNameAsString` which works
with special key names in C++.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18141

llvm-svn: 263426
2016-03-14 12:41:24 +00:00
Haojian Wu 0519744343 [clang-tidy] Make 'modernize-use-nullptr' check ignores NULL marcos used in other macros.
Reviewers: bkramer, alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17958

llvm-svn: 263221
2016-03-11 11:40:08 +00:00
Felix Berger adfdc14832 [clang-tidy] Extend UnnecessaryCopyInitialization check to trigger on non-const copies that can be safely converted to const references.
Summary:
Move code shared between UnnecessaryCopyInitialization and ForRangeCopyCheck into utilities files.
Add more test cases for UnnecessaryCopyInitialization and disable fixes inside of macros.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17488

llvm-svn: 262781
2016-03-05 21:17:58 +00:00
Haojian Wu 678f65a9b4 [clang-tidy] Make 'modernize-use-nullptr' check work on multiple nested implicit cast expressions.
Summary:
For some test cases like:

```
 int func(int, void*, void*);
(double)func(0, 0, 0);
```

The AST contains several `ImplicitCastExpr`s, so we should not only check on the first sub expression.

```
 `-CStyleCastExpr 0x7fe43a088938 <line:6:3, col:24> 'double' <NoOp>
      `-ImplicitCastExpr 0x7fe43a088920 <col:11, col:24> 'double' <IntegralToFloating>
        `-CallExpr 0x7fe43a0888a0 <col:11, col:24> 'int'
          |-ImplicitCastExpr 0x7fe43a088888 <col:11> 'int (*)(int, void *, void *)' <FunctionToPointerDecay>
          | `-DeclRefExpr 0x7fe43a0887d8 <col:11> 'int (int, void *, void *)' lvalue Function 0x7fe43a0886f0 'func1' 'int (int, void *, void *)'
          |-IntegerLiteral 0x7fe43a088800 <col:17> 'int' 0
          |-ImplicitCastExpr 0x7fe43a0888e0 <col:20> 'void *' <NullToPointer>
          | `-IntegerLiteral 0x7fe43a088820 <col:20> 'int' 0
          `-ImplicitCastExpr 0x7fe43a0888f8 <col:23> 'void *' <NullToPointer>
            `-IntegerLiteral 0x7fe43a088840 <col:23> 'int' 0
```

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17849

llvm-svn: 262698
2016-03-04 08:55:54 +00:00
Gabor Horvath 65c02ec837 [clang-tidy] Improve the robustness of a test.
llvm-svn: 262618
2016-03-03 13:43:23 +00:00
Gabor Horvath f4336ac9eb [clang-tidy] Do not emit warnings from misc-suspicious-semicolon when the compilation fails.
llvm-svn: 262615
2016-03-03 13:08:11 +00:00
Benjamin Kramer 8f5eb56df3 [clang-tidy] Add "clang-tidy as a clang plugin" skeleton.
This doesn't really do much at the moment. You can load it via libclang
and set the -checks via an extra command line argument as illustrated in
the test case. Support for other options (including headers check) is
currently missing. Also when using this with libclang some checks may
not work with the precompiled preamble in place.

This can be used to easily show clang-tidy warnings in an editor
integration as all that's needed is adding command line flags that are
passed into libclang. Warnings and FixIts are exposed via the existing
CXDiagnostic machinery.

Differential Revision: http://reviews.llvm.org/D17807

llvm-svn: 262595
2016-03-03 08:58:12 +00:00
Haojian Wu 7d08ba2749 [clang-tidy] Fix an assertion failure of "SLocEntry::getExpansion()" when IncludeInserter handles macro header file.
Summary: Also Fixes PR24749.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17805

llvm-svn: 262484
2016-03-02 14:12:17 +00:00
Haojian Wu 1b5b0fd174 [clang-tidy] Make 'modernize-pass-by-value' fix work on header files.
Reviewers: alexfh

Subscribers: jbcoe, cfe-commits

Differential Revision: http://reviews.llvm.org/D17756

llvm-svn: 262470
2016-03-02 09:01:25 +00:00
Haojian Wu 0d5e9d3135 [clang-tidy] Fix an assertion failure in `modernize-use-nullptr` check.
Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17640

llvm-svn: 262024
2016-02-26 15:34:35 +00:00
Haojian Wu f7692a2792 [clang-tidy] Fix a crash issue when clang-tidy runs with compilation database.
Summary:
The clang-tidy will trigger an assertion if it's not in the building directory.

TEST:
cd <llvm-repo>/
./build/bin/clang-tidy --checks=-*,modernize-use-nullptr -p build tools/clang/tools/extra/clang-tidy/ClangTidy.cpp

The crash issue is gone after applying this patch.

Fixes PR24834, PR26241

Reviewers: bkramer, alexfh

Subscribers: rizsotto.mailinglist, cfe-commits

Differential Revision: http://reviews.llvm.org/D17335

llvm-svn: 261991
2016-02-26 09:19:33 +00:00
Alexander Kornienko 1612fa07d3 Add a new check, readability-redundant-string-init, that checks unnecessary string initializations.
Reviewers: hokein, alexfh

Subscribers: cfe-commits

Patch by Shuai Wang!

Differential Revision: http://reviews.llvm.org/D17586

llvm-svn: 261939
2016-02-25 23:57:23 +00:00
NAKAMURA Takumi be16bbc925 Revert r261814, "check-clang-tools: Introduce the feature target-headers", corresponding to r261893.
llvm-svn: 261897
2016-02-25 16:59:59 +00:00
Alexander Kornienko f9c1e2c812 [clang-tidy] Adding headers needed in modernize-deprecated-headers tests
llvm-svn: 261893
2016-02-25 16:46:54 +00:00
NAKAMURA Takumi 8ef4887b15 check-clang-tools: Introduce the feature "target-headers".
For now, it just detects that host is non-Windows and target is msvc.

FIXME: It should be probable for cross compilations. Detect whether target's headers would be available.
llvm-svn: 261814
2016-02-25 01:12:57 +00:00
Alexander Kornienko e4a75fd896 [clang-tidy] introduce modernize-deprecated-headers check
Summary:
This patch introduces the modernize-deprecated-headers check, which is supposed to replace deprecated C library headers with the C++ STL-ones.

For information see documentation; for exmaples see the test cases.

Reviewers: Eugene.Zelenko, LegalizeAdulthood, alexfh

Subscribers: cfe-commits

Patch by Kirill Bobyrev!

Differential Revision: http://reviews.llvm.org/D17484

llvm-svn: 261738
2016-02-24 13:36:34 +00:00
Alexander Kornienko ea9fd99215 [clang-tidy] Added a check for forward declaration in the potentially wrong namespace
Adds a new check "misc-forward-declaration-namespace".
In check, A forward declaration is considerred in a potentially wrong namespace
if there is any definition/declaration with the same name exists in a different
namespace.

Reviewers: akuegel, hokein, alexfh

Patch by Eric Liu!

Differential Revision: http://reviews.llvm.org/D17195

llvm-svn: 261737
2016-02-24 13:35:32 +00:00
Aaron Ballman 527a420550 Add a new check, cert-env33-c, that diagnoses uses of system(), popen(), and _popen() to execute a command processor. This check corresponds to the CERT secure coding rule: https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=2130132
llvm-svn: 261530
2016-02-22 16:01:06 +00:00
Aaron Ballman 611d2e4ee6 Add a new check, cert-flp30-c, that diagnoses loop induction expressions of floating-point type. This check corresponds to the CERT secure coding rule: https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters
llvm-svn: 261324
2016-02-19 14:03:20 +00:00
Samuel Benzaquen 1fb8bc7a30 [clang-tidy] Match the type against the get() method we are calling,
instead of a get() method we find in the class.

The duck typed smart pointer class could have overloaded get() methods
and we should only skip the one that matches.

llvm-svn: 261102
2016-02-17 16:13:14 +00:00
Haojian Wu 6b4c0b5b66 [clang-tidy] Fix an assert failure in `modernize-loop-convert`.
Summary:
The test code will trigger following an assert failure:

assert.h assertion failed at LoopConvertUtils.cpp:560 in
bool clang::tidy::modernize::ForLoopIndexUseVisitor::TraverseMemberExpr(clang::MemberExpr*): ExprType->isPointerType() && "Operator-> returned non-pointer type"

Reviewers: alexfh

Differential Revision: http://reviews.llvm.org/D17287

llvm-svn: 260953
2016-02-16 10:36:51 +00:00
Haojian Wu 67f880641c [clang-tidy] Fix an assert failure of ForStmt in `readability-braces-around-statements` check.
Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17134

llvm-svn: 260952
2016-02-16 10:31:33 +00:00
NAKAMURA Takumi 2c2c461e2a clang-tools-extra/test/Unit/lit.site.cfg.in: Prune on_clone. I guess it has been unused since r188006.
llvm-svn: 260944
2016-02-16 08:13:36 +00:00
Felix Berger ffae543b39 [clang-tidy] ClangTidy check to flag uninitialized builtin and pointer fields.
Summary:
This patch is a continuation of http://reviews.llvm.org/D10553 by Jonathan B Coe.

The main additions are:

1. For C++11 the check suggests in-class field initialization as fix. This
makes the fields future proof towards the addition of new constructors.
2 For older language versions the fields are added in the right position
in the initializer list with more tests.
3. User documentation.

Reviewers: alexfh, jbcoe

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D16517

llvm-svn: 260873
2016-02-15 04:27:56 +00:00