1560 Commits

Author SHA1 Message Date
Edwin Vane
8d206f5149
[clang-tidy] Allow renaming macro arguments (#87792)
Although the identifier-naming.cpp lit test expected macro arguments not
to be renamed, the code seemed to already allow it. The code was simply
not being exercised because a SourceManager argument wasn't being
provided. With this change, renaming of macro arguments that expand to
renamable decls is permitted.
2024-04-10 07:40:35 -04:00
Danny Mösch
16b3e43a03
[clang-tidy] Ignore non-forwarded arguments if they are unused (#87832) 2024-04-08 23:54:29 +02:00
Edwin Vane
1107b47dcd
[clang-tidy] rename designated initializers (#86976)
readability-identifier-naming now supports renaming designated
initializers.
2024-04-08 11:22:19 -04:00
Danny Mösch
7a4e89761a
[clang-tidy] Add fix-its to readability-avoid-return-with-void-value check (#81420) 2024-04-07 13:28:29 +02:00
Mike
ed4e505c21
[clang-tidy] Fix readability-duplicate-include for includes with macro (#87433)
Completely skip include directives that form the filename using macros.

fixes #87303
2024-04-06 04:38:08 +03:00
Congcong Cai
ff1e72d68d
[clang-tidy] hicpp-ignored-remove-result ignore functions with same prefixes as the target (#87587) 2024-04-05 09:50:57 +08:00
Congcong Cai
3365d62179
[clang-tidy] add new check readability-enum-initial-value (#86129)
Fixes: #85243.
2024-04-01 15:53:57 +08:00
Piotr Zegar
80487e1c62 [clang-tidy][NFC] Reorder entrys in release notes
Sort entrys in release notes.
2024-03-26 21:10:06 +00:00
Félix-Antoine Constantin
8ea94b614b
[clang-tidy] Improved modernize-use-using by fixing a false-negative (#82947)
The check needs a parent decl to match but if the typedef is in a
function, the parent is a declStmt which is not a decl by itself.
Improved the matcher to match on either a decl or a declstmt and extract
the decl from the stmt in the latter case.

Fixes #72179
2024-03-26 20:39:05 +01:00
Piotr Zegar
5e6e40fee3
[clang-tidy] Improve performance of google-runtime-int (#86596)
Main problem with performance of this check is caused by hasAncestor
matcher, and to be more precise by an llvm::DenseSet and std::deque in
matchesAnyAncestorOf.

To reduce impact of this matcher, multiple conditions that were checked
in check method were copied into AST matcher that is now checked before
hasAncestor.

Using custom getCheckTraversalKind to exclude template instances that
shouldn't be checked anyway is an additional improvement, but gain from
that one is low.

Tested on ffl_tests.cc, visible reduction from ~442 seconds to ~15
seconds (~96% reduction).

Closes #86553
2024-03-26 20:19:23 +01:00
Piotr Zegar
313734795c
[clang-tidy] Fix fix-it overlaps in readability-static-definition-in-anonymous-namespace (#86599)
Because check emitted multiple warnings for every template instance
fix-it couldn't be applied due to overlaps.

Using TK_IgnoreUnlessSpelledInSource and restricting check to C++ only.
2024-03-26 18:20:25 +01:00
Piotr Zegar
d4a4585165
[clang-tidy] Ignore expresions in unevaluated context in bugprone-inc-dec-in-conditions (#85849)
Skip checking for references to variable in unevaluated context, like
decltype, static_assert and so on.

Closes #85838
2024-03-24 19:52:19 +01:00
Piotr Zegar
28c1279db3
[clang-tidy] Add bugprone-suspicious-stringview-data-usage check (#83716)
This check identifies suspicious usages of std::string_view::data() that
could lead to reading out-of-bounds data due to inadequate or incorrect
string null termination.

Closes #80854
2024-03-19 20:15:08 +01:00
Piotr Zegar
0a40f5d1a0
[clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory (#77246)
Implement proper support for lambdas and sub-functions/classes.
Moved from https://reviews.llvm.org/D157285

Fixes: #59389
2024-03-19 20:13:20 +01:00
Congcong Cai
4fdf10faf2
[clang-tidy]avoid bugprone-unused-return-value false positive for assignment operator overloading (#84489) 2024-03-09 23:08:51 +08:00
Piotr Zegar
9fb552812c
[clang-tidy] Fix Hungarian Prefix in readability-identifier-naming (#84236)
Fix handling of Hungarian Prefix when configured to LowerCase.
Warnings no longer will be emited for names that already match
this style.

Fixes: #80268
2024-03-08 18:34:26 +01:00
Congcong Cai
912ea6e335
[clang-tidy]avoid bugprone-unused-return-value false positive for function with the same prefix as the default argument (#84333) 2024-03-08 21:18:58 +08:00
Congcong Cai
84842f4b3b
[clang-tidy] bugprone-assert-side-effect can detect side effect from non-const reference parameters (#84095)
Fixes: #84092
2024-03-07 09:39:29 +08:00
Qizhi Hu
8b326d5946
[clang-tidy] fix false negative in cppcoreguidelines-missing-std-forward (#83987)
Try to fix https://github.com/llvm/llvm-project/issues/83845
When `std::forward` is invoked in a function, make sure it uses correct
parameter by checking if the bounded `var` equals the parameter.

Co-authored-by: huqizhi <836744285@qq.com>
2024-03-06 09:27:32 +08:00
isuckatcs
8e56fb824a
[clang-tidy] CRTP Constructor Accessibility Check (#82403)
Detects error-prone Curiously Recurring Template Pattern usage, when the CRTP
can be constructed outside itself and the derived class.
2024-03-05 01:09:39 +01:00
AMS21
b32845cb94
[clang-tidy] Let bugprone-use-after-move also handle calls to std::forward (#82673)
Add support for std::forward.

Fixes #82023
2024-03-04 19:56:15 +01:00
Félix-Antoine Constantin
0097fd2b06
[clang-tidy] bugprone-unused-return-value config now supports regexes (#82952)
The parameter `CheckedFunctions` now supports regexes

Fixes #63107
2024-03-04 19:05:06 +01:00
AMS21
eb3b063995
[clang-tidy] Improve google-explicit-constructor checks handling of explicit(bool) (#82689)
We now treat `explicit(false)` the same way we treat `noexcept(false)`
in the noexcept checks, which is ignoring it.

Also introduced a new warning message if a constructor has an `explicit`
declaration which evaluates to false and no longer emit a faulty FixIt.

Fixes #81121
2024-03-03 12:13:25 +01:00
Danny Mösch
525fe4492b
[clang-tidy] Add new check modernize-use-designated-initializers (#80541) 2024-02-29 20:48:05 +01:00
AMS21
7b11e2ec39
[clang-tidy] Fix cppcoreguidelines-missing-std-forward false positive for deleted functions (#83055)
Improved check by no longer giving false positives for deleted functions.
2024-02-27 19:35:11 +01:00
Clement Courbet
94ca854d3c
[clang-tidy] Add support for determining constness of more expressions. (#82617)
This uses a more systematic approach for determining whcich
`DeclRefExpr`s mutate the underlying object: Instead of using a few
matchers, we walk up the AST until we find a parent that we can prove
cannot change the underlying object.

This allows us to handle most address taking and dereference, bindings
to value and const& variables, and track constness of pointee (see
changes in DeclRefExprUtilsTest.cpp).

This allows supporting more patterns in
`performance-unnecessary-copy-initialization`.

Those two patterns are relatively common:

```
const auto e = (*vector_ptr)[i]
```

and

```
const auto e = vector_ptr->at(i);
```

In our codebase, we have around 25% additional findings from
`performance-unnecessary-copy-initialization` with this change. I did
not see any additional false positives.
2024-02-26 09:55:07 +01:00
Alexander Scholz
8dfc023e80
[run-clang-tidy.py] Add option to ignore source files from compilation database (#82416)
I added the option -source-filter to the
`run-clang-tidy.py` script in the clang-tools-extra.

This option allows for handing over a regex, to filter out source files
from the compilation database (not run `clang-tidy` on them).
2024-02-25 17:42:57 +01:00
Dmitry Polukhin
c3107821ae
[clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (#81985)
Summary:
Some build systems create symlinks in a temporary build directory for
headers in the source tree for isolation purposes. These symlinks
prevent `readability-identifier-naming` detecting issues and applying
fixes. Without this fix clang-tidy is checking .clang-tidy config file
in a temporary directory instead of source source location.

Test Plan: check-clang-tools
2024-02-19 10:02:24 +00:00
Danny Mösch
5e83b26584
[clang-tidy] Keep parentheses when replacing index access in sizeof calls (#82166)
Fixes #56021.
2024-02-18 22:42:17 +01:00
Piotr Zegar
3496927edc
[clang-tidy] Fixes to readability-implicit-bool-conversion (#72050)
- Fixed issue with invalid code being generated when static_cast is put
into fix, and no space were added before it.
- Fixed issue with duplicate parentheses being added when double
implicit cast is used.

Closes #71848
2024-02-18 12:30:43 +01:00
Piotr Zegar
75adb12269
[clang-tidy] Fix handling of parentheses in bugprone-non-zero-enum-to-bool-conversion (#81890)
Properly ignore parentheses in bitwise operators.

Closes #81515
2024-02-17 08:58:22 +01:00
Congcong Cai
e9cec39239
[clang-tidy] fix incorrect hint for InitListExpr in prefer-member-initializer (#81560) 2024-02-16 09:18:21 +08:00
Kevin Joseph
5992b3272b
[clangd] Clean formatting modernize-use-override (#81435)
When applying the recommended fix for the
"modernize-use-override" clang-tidy diagnostic
there was a stray whitespace. This PR fixes that.
Resolves https://github.com/clangd/clangd/issues/1704
2024-02-14 20:59:21 +01:00
Félix-Antoine Constantin
9b80ab4332
[clang-tidy] Removed redundant-inline-specifier warning on static data members (#81423)
Updated the check to ignore point static data members with in class
initializer since removing the inline specifier would generate a
compilation error

Fixes #80684
2024-02-14 20:30:21 +01:00
Congcong Cai
ebe77cc320
[clang-tidy] ignore local variable with [maybe_unused] attribute in bugprone-unused-local-non-trivial-variable (#81563) 2024-02-13 18:00:11 +08:00
Danny Mösch
00e80fbfb9
[NFC] Correct C++ standard names (#81421) 2024-02-11 19:43:34 +01:00
Piotr Zegar
d86f21693c [clang-tidy][NFC] Fixes in release notes and documentation
Minor fixes in documentation & release notes.
2024-02-09 18:20:01 +00:00
Shourya Goel
a7520d9727
[Clang-tidy] bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (#81183)
Changed LibASTMatcher to give an appropriate warning
when a const loop bound is initialized with a function declaration.

Fixes: #79580
2024-02-09 17:44:04 +01:00
Bhuminjay Soni
c13e271a38
Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (#77816)
This pull request fixes #64914 where author suggests adding a
readability check to propose the replacement of conditional statements
with std::min/std::max for improved code readability. Additionally,
reference is made to PyLint's similar checks:
[consider-using-min-builtin](https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/consider-using-min-builtin.html)
and
[consider-using-max-builtin](https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/consider-using-max-builtin.html)
2024-02-06 20:57:34 +01:00
Dmitry Polukhin
95403b42da
Apply format only if --format is specified (#79466)
clang-apply-replacements used to apply format even without --format is
specified. This because, methods like createReplacementsForHeaders only
takes the Spec.Style and would re-order the headers even when it was not
requested. The fix is to set up Spec.Style only if --format is provided.

Also added note to ReleaseNotes.rst

Based on https://github.com/llvm/llvm-project/pull/70801

---------

Co-authored-by: Kugan <34810920+kuganv@users.noreply.github.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-02-05 10:00:17 +00:00
Carlos Galvez
cc38cd856d
[clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (#80333)
…ationFileExtensions

Deprecated since clang-tidy 17. Use the corresponding global options
instead.

Fixes #61947

---------

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2024-02-02 21:48:21 +01:00
Carlos Galvez
6f32d6a4f3
[clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-prefer-member-init (#80330)
This functionality already exists in
cppcoreguidelines-use-default-member-init. It was deprecated from this
check in clang-tidy 17.

This allows us to fully decouple this check from the corresponding
modernize check, which has an unhealthy dependency.

Fixes https://github.com/llvm/llvm-project/issues/62169

---------

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2024-02-01 21:16:24 +01:00
Piotr Zegar
b777bb78b3
[clang-tidy] Add AllowStringArrays option to modernize-avoid-c-arrays (#71701)
Add AllowStringArrays option, enabling the exclusion of array types with
deduced sizes constructed from string literals. This includes only var
declarations of array of characters constructed directly from c-strings.

Closes #59475
2024-02-01 06:47:53 +01:00
Carlos Galvez
4cb13f2d23
[clang-tidy] Remove cert-dcl21-cpp check (#80181)
Deprecated since clang-tidy 17. The rule DCL21-CPP has been removed from
the CERT guidelines, so it does not make sense to keep the check.

Fixes #42788

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2024-01-31 20:35:28 +01:00
Tom Stellard
987087df90 Bump trunk version to 19.0.0git 2024-01-23 19:00:11 -08:00
Piotr Zegar
150a58bed0 [clang-tidy][DOC] Update list.rst
Update list.rst to put checks in alphabetical order
2024-01-23 07:09:24 +00:00
Félix-Antoine Constantin
ee0b4d9681
[clang-tidy] Ignore user-defined literals in google-runtime-int (#78859)
User-defined literals do not accept u?intXX(_t)? variables. So the check
should not emit a warning.

Fixes #54546 #25214
2024-01-23 00:14:30 +01:00
Julian Schmidt
9f8ccf50dd
[clang-tidy] fix misc-const-correctnes false-positive for fold expressions (#78320)
The check no longer emits a diagnostic for non-parameter-pack 
variables in C++17 fold expressions.
The operator used is type-dependent because of the parameter pack
and can therefore not be guaranteed to not mutate the variable.

Fixes: #70323
2024-01-22 21:51:39 +01:00
Piotr Zegar
06c3c3b67c
[clang-tidy] Add bugprone-chained-comparison check (#76365)
Check that flags chained comparison expressions,
such as a < b < c or a == b == c, which may have
unintended behavior due to implicit operator
associativity.

Moved from Phabricator  (D144429).
2024-01-22 17:11:02 +01:00
Piotr Zegar
6a80e56ad0
[clang-tidy] Fix macros handling in cppcoreguidelines-prefer-member-initializer (#72037)
Produces now valid fixes for a member variables initialized with macros.
Correctly uses expansion location instead of location inside macro to
get init code.

Close #70189
2024-01-22 16:17:33 +01:00