1045 Commits

Author SHA1 Message Date
Tom Stellard
3bd3e06f3f
Bump version to 21.0.0git (#124870)
Also clear the release notes.
2025-01-28 19:48:43 -08:00
qt-tatiana
aa580c2ec5
[clang-tidy] Add EnableQtSupport option to modernize-use-integer-sign-comprison (#122127)
- add an option `EnableQtSupport`, that makes C++17 `q20::cmp_*`
alternative available for Qt-based applications.
2025-01-22 23:30:53 +08:00
Congcong Cai
361f363c11
[clang-tidy]fix incorrect fix-it for the string contains a user-defined suffix (#122901)
Fixed: #97243
2025-01-17 21:41:48 +08:00
zotnhucucbot
bc74625f50
[clang-tidy] Add an option to exclude files not present in the compile database (#120348)
A change list may include files that are not part of the compile
database, which can cause clang-tidy to fail (e.g., due to missing
included headers). To prevent false negatives, we should allow to skip
processing these files.
2025-01-15 07:59:03 +08:00
Congcong Cai
a53fa78e7b
[clang-tidy][doc] fix incorrectly performance-unnecessary-copy-initialization link in release note (#122910) 2025-01-14 22:44:05 +08:00
Congcong Cai
ab023199d5
[clang-tidy] fix wrong float to float conversion check when floating point type is not standard type (#122637)
compare type kind is the wrong way to compare floating point type compatibility.
more generic compatibility check is needed.
2025-01-14 06:15:50 +08:00
MichelleCDjunaidi
8ebc35f8d0
[clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (#102299)
This checks that classes/structs inheriting from
``std::enable_shared_from_this`` does so with public inheritance, so it
prevents crashes due to ``std::make_shared`` and ``shared_from_this()``
getting called when the internal weak pointer was not initialized (e.g.
due to private inheritance).
2025-01-12 11:04:40 +01:00
Barnabás Pőcze
a5364444bd
[clang-tidy] performance-unnecessary-copy-initialization: Consider static functions (#119974)
Static member functions can be considered the same way as free functions
are, so do that.
2025-01-12 10:07:52 +01:00
Congcong Cai
2c7829e676
[clang-tidy][doc] combine the clang-tidy itself's change together in release note (#122594)
<img width="1137" alt="image"
src="https://github.com/user-attachments/assets/25433743-2c19-422a-93c5-3edfc1bb7a3f"
/>
2025-01-12 06:48:46 +08:00
Congcong Cai
32351b5450
[clang-tidy][doc] fix incorrectly code snippet in release note (#122595) 2025-01-11 23:26:34 +08:00
Congcong Cai
0249554ee1
[clang-tidy] fix incorrect configuration file path resolving when file paths contain .. (#121323)
`makeAbsolute` will not normalize path. When getting parent folder, `..`
will go into the subfolder instead of the parent folder.
2025-01-11 22:51:47 +08:00
Congcong Cai
32bcd41adc
[clang-tidy] use correct template type in `std::min and std::max` when operand is integer literal for readability-use-std-min-max (#122296)
When comparing with integer literal, integer promote will happen to
promote type which has less bit width than int to int or unsigned int.
It will let auto-fix provide correct but out of expected fix.

e.g.
```c++
short a;
if ( a > 10 )
  a = 10;
```
will be
```c++
short a;
if ( (int)a > 10 )
  a = (short)10;
```

which will be fixed as
```c++
short a;
a = std::max<int>(a, 10);
```

but actually it can be
```c++
short a;
a = std::max<short>(a, 10);
```

Fixed: #121676
2025-01-11 18:48:39 +08:00
Tommy Chen
dc2963c8d7
[clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (#109741)
Exclude CXXParenListInitExpr from RedundantCastingCheck because there
are false positive cases. Currently, we can't think of positive cases
for CXXParenListInitExpr. This can be improved by following the
initListExpr method if we can come up with some positive cases.

Fixes #108846
2025-01-11 11:04:19 +01:00
Jan Voung
749bdc87f5
[clang-tidy] sort / reorder a part of release notes (#122475)
and remove a trailing space
2025-01-10 15:14:27 -05:00
maflcko
6504546abc
[clang-tidy][use-internal-linkage] fix false positive for consteval function (#122141)
Fixes https://github.com/llvm/llvm-project/issues/122096

---------

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
2025-01-10 09:24:24 +01:00
Congcong Cai
c01ffab6e1 [clang-tidy][doc] reorder release note 2025-01-09 23:25:33 +08:00
Congcong Cai
72b6a57363
[clang-tidy] fix false positives when using name-independent variables after C++26 for bugprone-unused-local-non-trivial-variable (#121783)
Fixed: #121731
According to https://eel.is/c++draft/basic.scope.scope#5, name
independent declaration should not be warned as unused
2025-01-08 20:56:49 +08:00
flovent
c27483763c
[clang-tidy] bugprone-unhandled-self-assignment: fix smart pointer check against std::unique_ptr type (#121266)
Unlike other standard smart pointer types, std::unique_ptr has two
template arguments.
testcase need to be updated too.
2025-01-07 20:56:21 +08:00
Congcong Cai
42dfaa15a6
[clang-tidy] add depercation warning for non-whitelisted global options (#121057)
We plan to depercate `StrictMode` and `IgnoreMacros` global options
after 2 major versions and support local options only for them.
This patch introduces the depercation warning.
2024-12-30 22:35:46 +08:00
Congcong Cai
e45e091b90
[clang-tidy] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions (#120245)
According to #116591.
> Coding guidelines should "cherry-pick" (and posddsibly
configure/harden/make more strict) base checks.
We should move narrowing conversion to bugprone and keep alias in
cppcoreguidelines
2024-12-29 19:22:25 +08:00
NAKAMURA Takumi
537d4e9d21 Revert "Added options to readability-implicit-bool-conversion (#120087)"
This reverts commit 5bec2b71b44ddff44aa4d8534b58a5561389bb1d.
(llvmorg-20-init-16425-g5bec2b71b44d)

This broke tests.
2024-12-28 17:47:00 +09:00
4m4n-x-B4w4ne
5bec2b71b4
Added options to readability-implicit-bool-conversion (#120087)
As given in the issue #36323 , I added two new options in the
clang-tools-extra/clan-tidy/readibility/ImplicitBoolConversionCheck.cpp
and header file.
I have also written new test cases to test these new options in
test/readibility directory.
2024-12-28 15:35:30 +08:00
Congcong Cai
2ff614aaa6
[clang-tidy] support parameters file in command line (#120547)
Fixes: #103499
2024-12-24 23:24:14 +08:00
Julian Schmidt
f77152d9a4
[clang-tidy] use specified type verbatim in modernize-use-using fix (#113837)
Previously, the implementation used the printed type, which contains
expanded
macro arguments, deletes comments, and removes function argument names 
from the alias declaration. Instead, this check can be more surgical and
use the
actual written type verbatim.

Fixes #33760
Fixes #37846
Fixes #41685
Fixes #83568
Fixes #95716
Fixes #97009
2024-12-21 13:06:30 +01:00
Congcong Cai
222dd235ff
[clang-tidy] use local config (#120004)
follow up patch for #119948.
2024-12-18 18:38:46 +08:00
Congcong Cai
ba373a222f
[clang-tidy]detecting conversion directly by make_unique and make_shared in bugprone-optional-value-conversion (#119371)
Inspired by #110964
2024-12-12 06:55:29 +08:00
qt-tatiana
8b63bfbf6d
[clang-tidy] Create a check for signed and unsigned integers comparison (#113144)
- modernize-use-integer-sign-comparison replaces comparisons between
signed and unsigned integers with their safe C++20 ``std::cmp_*``
alternative, if available.
2024-12-12 00:38:05 +08:00
Congcong Cai
a07e8cdae7
[clang-tidy] fix false positive in lambda expr for return-const-ref-from-parameter (#118990)
We should bind the node in `hasAncestor` matcher and `equalsBoundNode`
in the other matcher because `hasAncestor` will visit the ancestor until
to find the matched result.
2024-12-07 08:31:35 +08:00
Congcong Cai
57907c1a96
[clang-tidy] ignore [[clang::lifetimebound]] param in return-const-ref-from-parameter (#118315)
Fixed #117696
2024-12-03 22:25:29 +08:00
Congcong Cai
010317e173
[clang-tidy][use-internal-linkage]fix false positives for ExportDecl (#117901)
Fixed: #97190
2024-12-02 13:59:55 +08:00
Congcong Cai
f89fa238fa
[clang-tidy][use-internal-linkage]fix false positives for global overloaded operator new and operator delete (#117945) 2024-11-30 22:14:36 +08:00
Qizhi Hu
04ab599363
[clang-tidy] fix false positive in bugprone-return-const-ref-from-parameter (#117734)
Fix https://github.com/llvm/llvm-project/issues/115743
2024-11-30 08:29:28 +08:00
vabridgers
8ac2b77a11
[analyzer] Remove alpha.core.IdenticalExpr Checker (#114715)
This change removes the alpha.core.IdenticalExpr static analysis checker
since it's checks are present in the clang-tidy checks
misc-redundant-expression and bugprone-branch-clone. This check was
implemented as a static analysis check using AST matching, and since
alpha and duplicated in 2 clang-tidy checks may be removed.

Co-authored-by: Vince Bridgers <vince.a.bridgers@ericsson.com>
2024-11-29 17:38:59 -06:00
Helmut Januschka
508448280a
[clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (#116033)
Enhances the modernize-use-starts-ends-with check to detect additional patterns
using substr that can be replaced with starts_with() (C++20).
This enhancement improves code readability and can be more efficient by avoiding
temporary string creation.
2024-11-26 21:15:02 -05:00
ykiko
ec4c47d949
Add code completion for C++20 keywords. (#107982)
This commit adds code completion for C++20 keywords, fix
https://github.com/llvm/llvm-project/issues/107868.

1. complete `concept` in template context
    - [x] `template<typename T> conce^` -> `concept`
    - [ ] `conce^`

2. complete `requires` 
- [x] constraints in template context: `template<typename T> requi^` ->
`requires`
- [x] requires expression: `int x = requ^` -> `requires (parameters) {
requirements }`
- [x] nested requirement: `requires { requ^ }` -> `requires expression
;`

3. complete coroutine keywords
    - [x] `co_await^` in expression: `co_aw^` -> `co_await expression;`
- [x] `co_yield` in function body: `co_yi^` -> `co_yield expression;`
- [x] `co_return` in function body: `co_re^` -> `co_return expression;`

4. specifiers: `char8_t`, `consteval`, `constinit`
2024-11-26 13:03:39 +01:00
Congcong Cai
605b8dad5c
[clang-tidy] Fix false positive in cppcoreguidelines-avoid-const-or-ref-data-members when detecting templated classes with inheritance (#115180)
`hasSimpleCopyConstructor` series of functions are not reliable when
these functions are not resolved. We need to manually resolve the status
of these functions from its base classes.
Fixes: #111985.
2024-11-25 06:47:22 +08:00
Congcong Cai
e3aafe407a
[clang-tidy] fix false positive use-internal-linkage for func decl without body (#117490)
If in one TU, function only have declaration without body, this function
should be external linkage.
Fixed #117488
2024-11-25 06:46:10 +08:00
Congcong Cai
0c21ed48f4
[clang-tidy][NFC] fix release note order (#117484) 2024-11-24 21:46:39 +08:00
Congcong Cai
fd2e0483de
[clang-tidy] ignore consteval function in ExceptionAnalyzer (#116643)
`ExceptionAnalyzer` can ignore `consteval` function even if it will
throw exception. `consteval` function must produce compile-time
constant. But throw statement cannot appear in constant evaluation.
Fixed: #104457.
2024-11-22 05:01:49 +08:00
higher-performance
0b344b4fef
Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (#114255)
These need to be handled similarly to the standard smart pointers; they
all have a `reset` method.
2024-11-16 00:47:52 +08:00
Julian Schmidt
9ae21b073a
[clangd] fix extract-to-function for overloaded operators (#81640)
When selecting code that contains the use of overloaded operators,
the SelectionTree will attribute the operator to the operator
declaration, not to the `CXXOperatorCallExpr`. To allow
extract-to-function to work with these operators, make unselected
`CXXOperatorCallExpr`s valid root statements, just like `DeclStmt`s.

Partially fixes clangd/clangd#1254

---------

Co-authored-by: Nathan Ridge <zeratul976@hotmail.com>
2024-11-15 01:05:20 -05:00
Congcong Cai
e855feac41
[clang-tidy] fix bugprone-sizeof-expression when sizeof expression with template types (#115275)
Fixed: #115175.
`dependent type` are not the same even pointers are the same.

---------

Co-authored-by: whisperity <whisperity@gmail.com>
2024-11-12 11:36:33 +08:00
Julian Schmidt
028ea71fdd
[clang-tidy] fix insertion location for function pointers in cppcoreguidelines-init-variables (#112091)
Previously, the insertion location for the `= nullptr` fix would be
after the variable name. However, if the variable is of type function
pointer that is not an alias, then the insertion would happen inside the
type specification: `void (*a1)(void*);` -> `void (*a1 =
nullptr)(void*);`.
With this change, the insertion location will be at the next
'terminator'. That is, at the next `,` or `;`, as that will finish the
current declaration: `void (a1)(void*) = nullptr;`.

Fixes #112089
2024-11-10 18:26:42 +01:00
Carlos Galvez
69fb9bcde0
Fix false positive in bugprone-throw-keyword-missing (#115302)
Fixes #115055

---------

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2024-11-09 22:04:17 +01:00
Ding Fei
03f06b9710
[clang-query] add basic profiling on matching each ASTs (#114806)
We've found that basic profiling could help improving/optimizing when
developing clang-tidy checks.

This PR adds an extra command
```
set enable-profile (true|false)   Set whether to enable matcher profiling.
```
which enables profiling queries on each file.

Sample output:

```
$ cat test.cql
set enable-profile true
m binaryOperator(isExpansionInMainFile())

$ cat test.c
int test(int i, int j) {
  return i + j;
}

$ clang-query --track-memory -f test.cql test.c --

Match #1:

{{.*}}/test.c:2:10: note: "root" binds here
    2 |   return i + j;
      |          ^~~~~
1 match.
===-------------------------------------------------------------------------===
                         clang-query matcher profiling
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0000 seconds (0.0000 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  ---Mem---  --- Name ---
   0.0000 (100.0%)   0.0000 (100.0%)   0.0000 (100.0%)   0.0000 (100.0%)        224  {{.*}}/test.c
   0.0000 (100.0%)   0.0000 (100.0%)   0.0000 (100.0%)   0.0000 (100.0%)        224  Total
```
2024-11-05 21:30:58 +08:00
Julian Schmidt
0edaba1b29
[clang-tidy] fix crash in altera-id-dependent-backward-branch (#113833)
Add some checks for `nullptr` and change some `dyn_cast` to
`dyn_cast_if_present` to avoid crashes.

Fixes #55408
2024-11-02 12:08:35 +01:00
Julian Schmidt
a776bd1a92
[clang-tidy] support return c ? a : b; in bugprone-return-const-ref-from-parameter (#107657)
A `const &` parameter can also be returned via a conditional operator:
`c ? a : b`. This change adds support for diagnosing returning these
parameters
with conditional operators.
2024-10-31 09:13:51 +01:00
z1nke
27ef549af2
[clang-tidy] Fix crash in modernize-use-designated-initializers check (#113688)
Fix #113652.

When calling `Node.isAggregate()` and `Node.isPOD()`, if `Node` is declared but
not defined, it will result in null pointer dereference (and if assertions are
enabled, it will cause an assertion failure).
2024-10-29 15:48:39 -04:00
Discookie
f5ff3a560f
[clang-tidy] Do not emit file path for anonymous enums in readability-enum-initial-value check (#112496)
Previously the name of anonymous enums in the check were `enum 'enum
(unnamed at /full/path/to/file.c:1:1)'`, which breaks reproducibility of
clang-tidy reports when the analyzed project is in a different folder.
2024-10-28 11:19:22 +00:00
vabridgers
3d6923dbac
RFC: [clang-tidy] [analyzer] Move nondeterministic pointer usage check to tidy (#110471)
This change moves the `alpha.nondeterministic.PointerSorting` and
`alpha.nondeterministic.PointerIteration` static analyzer checkers to a
single `clang-tidy` check. Those checkers were implemented as simple
`clang-tidy` check-like code, wrapped in the static analyzer framework.
The documentation was updated to describe what the checks can and cannot
do, and testing was completed on a broad set of open-source projects.

Co-authored-by: Vince Bridgers <vince.a.bridgers@ericsson.com>
2024-10-28 03:53:36 -05:00