Commit Graph

119 Commits

Author SHA1 Message Date
Piotr Padlewski d57be707b8 [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix
Summary:
Bugfix for 27321. When the constructor of stored pointer
type is private then it is invalid to change it to
make_shared or make_unique.

Reviewers: alexfh, aaron.ballman, hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D23343

llvm-svn: 280180
2016-08-31 00:06:55 +00:00
Martin Bohme e9a265a267 Adapt to TraverseLambdaCapture interface change from D23204
Summary:
Depends on D23204.

This is intended to be submitted immediately after D23204 lands.

Reviewers: jdennett, alexfh

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D23543

llvm-svn: 278934
2016-08-17 15:00:22 +00:00
Kirill Bobyrev 8694cb97c2 [clang-tidy] minor improvements in modernise-deprecated-headers check
This patch introduces a minor list of changes as proposed by Richard Smith in
the mailing list.

See original comments with an impact on the future check state below:

[comments.begin

> +                          {"complex.h", "ccomplex"},

It'd be better to convert this one to <complex>, or leave it alone.
<ccomplex> is an unnecessary wart.

(The contents of C++11's <complex.h> / <ccomplex> / <complex> (all of
which are identical) aren't comparable to C99's <complex.h>, so if
this was C++98 code using the C99 header, the code will be broken with
or without this transformation.)

> +                          {"iso646.h", "ciso646"},

Just delete #includes of this one. <ciso646> does nothing.

> +              {"stdalign.h", "cstdalign"},
> +              {"stdbool.h", "cstdbool"},

We should just delete these two includes. These headers do nothing in C++.

comments.end]

Reviewers: alexfh, aaron.ballman

Differential Revision: https://reviews.llvm.org/D17990

llvm-svn: 278254
2016-08-10 18:01:45 +00:00
Kirill Bobyrev 75de8968b6 [clang-tidy] enhance modernize-use-bool-literals to check ternary operator
modernize-use-bool-literals doesn't checks operands in ternary operator.

For example:

``` c++
static int Value = 1;

bool foo() {
  bool Result = Value == 1 ? 1 : 0;
  return Result;
}

bool boo() {
  return Value == 1 ? 1 : 0;
}
```

This issue was reported in bug 28854. The patch fixes it.

Reviewers: alexfh, aaron.ballman, Prazek

Subscribers: Prazek, Eugene.Zelenko

Differential Revision: https://reviews.llvm.org/D23243

llvm-svn: 278022
2016-08-08 17:11:56 +00:00
Kirill Bobyrev 11cea45cce [clang-tidy] remove trailing whitespaces and retab
llvm-svn: 277340
2016-08-01 12:06:18 +00:00
Martin Bohme d10be62383 [clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566
Summary:
D22566 will change RecursiveASTVisitor so that it descends into the initialization expressions for lambda captures.

modernize-loop-convert needs to be prepared for this so that it does not interpret these initialization expressions as invalid uses of the loop variable. The change has no ill effects without D22566 in place, i.e. the change does not depend on D22566.

Reviewers: klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D22903

llvm-svn: 277339
2016-08-01 11:29:17 +00:00
Piotr Padlewski 8f80229109 [clang-tidy] Fixes to modernize-use-emplace
Not everything is valid, but it should works for 99.8% cases

https://reviews.llvm.org/D22208

llvm-svn: 277097
2016-07-29 02:10:23 +00:00
Matthias Gehre 056237a457 clang-tidy modernize-loop-convert: preserve type of alias declaration (bug 28341)
Summary:
Previoly, the added test failed with the fillowing fixit:

     char v[5];

-    for(size_t i = 0; i < 5; ++i)
+    for(char value : v)
     {
-        unsigned char value = v[i];
         if (value > 127)

i.e. the variable 'value' changes from unsigned char to signed char. And
thus the following 'if' does not work anymore.

With this commit, the fixit is changed to:
     char v[5];

-    for(size_t i = 0; i < 5; ++i)
+    for(unsigned char value : v)
     {
-        unsigned char value = v[i];
         if (value > 127)

Reviewers: alexfh, klimek

Subscribers: cfe-commits

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

llvm-svn: 276111
2016-07-20 12:32:06 +00:00
Krystyna Gajczyk c37933a12a [clang-tidy] Add modernize-use-using
http://reviews.llvm.org/D18919

llvm-svn: 273786
2016-06-25 18:37:53 +00:00
Cong Liu 998fb5c28b Remove ignoringImplicit from clang-tidy.
llvm-svn: 273660
2016-06-24 09:39:28 +00:00
Tim Shen 325c727480 Fix clang-tidy patterns to adapt to newly added ExprWithCleanups nodes.
Summary: This is a fix for the new ExprWithCleanups introduced by clang's temporary variable lifetime marks change.

Reviewers: bkramer, sbenza, angelgarcia, alexth

Subscribers: rsmith, cfe-commits

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

llvm-svn: 273310
2016-06-21 20:11:20 +00:00
Piotr Padlewski 552d449482 [clang-tidy] Add modernize-use-emplace
Summary: Add check that replaces call of push_back to emplace_back

Reviewers: hokein

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

llvm-svn: 273275
2016-06-21 15:23:27 +00:00
Alexander Kornienko c9c8290251 [clang-tidy] Fix doxygen errors. NFC.
llvm-svn: 272994
2016-06-17 11:43:33 +00:00
Benjamin Kramer 6f90dcc609 [clang-tidy] Remove dead code. NFC.
llvm-svn: 272803
2016-06-15 16:51:04 +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
Piotr Padlewski e93a73fb7a [ASTMatchers] Added ignoringParenImpCasts to has matchers
has matcher changed behaviour, and now it matches "as is" and
doesn't skip implicit and paren casts

http://reviews.llvm.org/D20801

llvm-svn: 271289
2016-05-31 15:26:56 +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
Etienne Bergeron e15ef2f609 [clang-tidy] Lift common matchers to utils namespace
Summary:
This patch is lifting matchers used by more than one checkers
to the common namespace.

Reviewers: aaron.ballman, alexfh

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 269804
2016-05-17 19:36:09 +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
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
Etienne Bergeron 2a4c00f243 [clang-tidy] Cleanup namespace in utils folder.
Summary:
This is a step forward cleaning up the namespaces in clang-tidy/utils.
There is no behavior change.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 268356
2016-05-03 02:54:05 +00:00
Eugene Zelenko a19859d589 [Clang-tidy] Fix Clang-tidy modernize-use-override and some Include What You Use warnings in modernize/MakeSmartPtrCheck.h.
llvm-svn: 268349
2016-05-03 01:13:27 +00:00
Etienne Bergeron 456177b98f [clang-tidy] Cleaning namespaces to be more consistant across checkers.
Summary:
The goal of the patch is to bring checkers in their appropriate namespace.
This path doesn't change any behavior.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 268264
2016-05-02 18:00:29 +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
Piotr Padlewski 74ca1cc7d0 small reformat to test access
llvm-svn: 268076
2016-04-29 17:45:20 +00:00
Etienne Bergeron 9d26599078 [clang-tidy] Cleanup some ast-matchers and lift some to utils.
Summary:
Little cleanup to lift-out and to remove some frequently used
ast-matchers.

Some of theses matchers are candidates to be lifted to ASTMatchers.h.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 267003
2016-04-21 16:57:56 +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
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
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
Richard Thomson 8930aab886 clang-tidy: Add check modernize-raw-string-literal
llvm-svn: 264539
2016-03-27 16:43:44 +00:00
Aaron Ballman 73a7bd3616 Fix crashes from delayed template parsing code that assumed getBody() would return non-null.
Patch by Etienne Bergeron.

llvm-svn: 264049
2016-03-22 13:37:44 +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
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
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
Alexander Kornienko 4f933376cf [clang-tidy] Another attempt to fix MSVC build
llvm-svn: 261811
2016-02-25 00:39:11 +00:00
Alexander Kornienko 4432e12918 Trying to fix MSVC build
llvm-svn: 261806
2016-02-24 23:48:24 +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
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
Alexander Kornienko f8bb8c5891 [clang-tidy] Enhance modernize-redundant-void-arg check to apply fixes to header files
Fixes http://llvm.org/PR25894

Patch by Richard Thomson!

Differential revision: http://reviews.llvm.org/D16953

llvm-svn: 260948
2016-02-16 09:49:05 +00:00
Haojian Wu 1e3c32b38a [clang-tidy] Fix assertion failure on `at` function in modernize-loop-convert.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260107
2016-02-08 15:59:42 +00:00
Chris Bieneman 2cc7fec76a Remove autoconf support
Summary:
This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html

"Now I am become Death, the destroyer of worlds."
-J. Robert Oppenheimer

Reviewers: chandlerc, grosbach, bob.wilson, echristo

Subscribers: cfe-commits, klimek

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

llvm-svn: 258864
2016-01-26 21:31:36 +00:00
Aaron Ballman b61829887d Make modernize-use-default tolerant of delayed template parsing; this code was previously causing failed assertions because dyn_cast was being passed a null pointer due to the delay-parsed body.
llvm-svn: 258356
2016-01-20 22:14:10 +00:00
Craig Topper 506dad8e55 Replace a dyn_cast with isa where the result was only being used as a boolean. NFC.
llvm-svn: 253442
2015-11-18 07:08:11 +00:00
Angel Garcia Gomez 2c19d4cee3 Allow the alias to be of a different type.
Summary: Consider a declaration an alias even if it doesn't have the same unqualified type than the container element, as long as one can be converted to the other using only implicit casts.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

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

llvm-svn: 252315
2015-11-06 15:47:04 +00:00
Angel Garcia Gomez 7056f7488f Use the old index identifier by default, instead of 'elem'.
Summary: Use the old index name in the cases where the check would come up with an invented name.

Reviewers: klimek

Subscribers: cfe-commits

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

llvm-svn: 252308
2015-11-06 15:03:14 +00:00
Angel Garcia Gomez 7e1d4ae937 Avoid naming conflicts with the old index in modernize-loop-convert.
Summary: The old index declaration is going to be removed anyway, so we can reuse its name if it is the best candidate for the new index.

Reviewers: klimek

Subscribers: cfe-commits, alexfh

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

llvm-svn: 252303
2015-11-06 14:04:12 +00:00