288 Commits

Author SHA1 Message Date
Dimitrije Dobrota
6a57af8d03
[clang-tidy] Add flag to specify an alternative to std::forward (#138755)
Since std::forward is nothing more than a cast, part of STL and not the
language itself, it's easy to provide a custom implementation if one
wishes not to include the entirety of <utility>.

Added flag (ForwardFunction) provides a way to continue using this
essential check even with the custom implementation of forwarding.

---------

Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
2025-06-30 22:13:33 +03:00
Baranov Victor
e435558ff9
[clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (#143550) 2025-06-24 08:39:05 +03:00
Baranov Victor
05491e0359
[clang-tidy] add 'IgnoreMarcos' option to 'avoid-goto' check (#143554) 2025-06-23 16:27:18 +03:00
Philipp Jung
669627d0c7
Add check 'cppcoreguidelines-use-enum-class' (#138282)
Warn on non-class enum definitions as suggested by the Core Guidelines:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-class
2025-06-18 11:02:53 +02:00
Baranov Victor
94877ce1b4
[clang-tidy][NFC] fix 'misc-use-internal-linkage' check warnings (#143482)
Run misc-use-internal-linkage check over clang-tidy code. 
Also fixed a couple of other clang-tidy warnings.

Apart from issues in header files, all '.cpp' in
`clang-tools-extra/clang-tidy` must be clang-tidy clear now.
2025-06-10 23:23:37 +03:00
Baranov Victor
68070f908b
[clang-tidy][NFC] run clang-format over 'cert', 'cppcore', 'fuchsia',… (#143316)
… 'google' checks
2025-06-08 23:22:55 +03:00
Kazu Hirata
ba007a60d0
[clang-tidy] Remove unused includes (NFC) (#141420)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-25 10:55:36 -07:00
Yanzuo Liu
b7db2e1fc0
[Clang-Tidy][NFC] Simplify check cppcoreguidelines-missing-std-forward (#138504)
Remove `CaptureInCopy` because the cases handled by it are covered by
`CaptureByRefExplicit`.
2025-05-07 21:39:31 +02:00
Congcong Cai
b34ed25dd5 [clang-tidy][NFC] add link libs for bugprone module
Fixed bug issue introduced in #120245
2024-12-29 19:51:55 +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
Congcong Cai
aaadaee7b2
[clang-tidy] remove misuse of getLocalOrGlobal for non common used options (#119948)
[RFC](https://discourse.llvm.org/t/rfc-global-option-rules-for-clang-tidy/83647)
2024-12-15 05:04:32 +08: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
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
Konstantin Romanov
0fbf91ab8e
[clang-tidy] Fix cppcoreguidelines-pro-type-union-access if memLoc is invalid (#104540)
Fixes #102945.
2024-10-22 17:05:00 -07:00
Kazu Hirata
c911b0a73c
[clang-tidy] Avoid repeated hash lookups (NFC) (#111628) 2024-10-09 06:45:44 -07:00
Thomas Fransham
1f2c08b33b
[clang-tools-extra] Fix add_clang_library usage (#109321)
If a add_clang_library call doesn't specify building as static or shared
library they are implicitly added to the list static libraries that is
linked in to clang-cpp shared library here.

315ba77406/clang/cmake/modules/AddClang.cmake (L107)
Because the clang-tools-extra libraries targets were declared after
clang-cpp they by luck never got linked to clang-cpp.
This change is required for clang symbol visibility macros on windows to
work correctly for clang tools since we need to distinguish if a target
being built will be importing or exporting clang symbols from the
clang-cpp DLL.
2024-10-08 09:22:19 +03:00
Congcong Cai
7deca859e5
[clang-tidy] fix false positive when member initialization depends on structured binging variable in cppcoreguidelines-prefer-member-initializer (#108743)
Fixes: #82970

Detecting dependiences with `varDecl` is too strict. It will ignore the
`bingingDecl`.
This patch wants to use `valueDecl` to match more cases including
`bingingDecl`.
2024-09-16 09:04:32 +08:00
Kazu Hirata
33ceb2dd75
[clang-tidy] Avoid repeated hash lookups (NFC) (#107490) 2024-09-05 19:04:30 -07:00
Pascal Jungblut
7c50187b7d
[clang-tidy] Option to ignore anonymous namespaces in avoid-non-const-global-variables (#93827)
Add an option to ignore warnings for cppcoreguidelines
avoid-non-const-global-variables.

Understandably, the core guidelines discourage non const global
variables, even at the TU level (see
https://github.com/isocpp/CppCoreGuidelines/issues/2195). However,
having a small TU with an interface that uses a non const variable from
an anonymous namespace can be a valid choice.

This adds an option that disables the warning just for anonymous
namespaces, i.e. at the file level. The default is still to show a
warning, just as before.
2024-07-01 21:12:42 +02:00
Congcong Cai
b06da39cae
[clang-tidy] ignoring macro with hash preprocessing token in cppcoreguidelines-macro-usage (#95265)
`#` and `##` preprocessing tokens cannot be replaced by constexpr
function. It should be ignored in check.
2024-06-13 09:36:33 +08:00
Piotr Zegar
54c6ee922a
[clang-tidy] Add AllowImplicitlyDeletedCopyOrMove option to cppcoreguidelines-special-member-functions (#71683)
Improved cppcoreguidelines-special-member-functions check with a new
option AllowImplicitlyDeletedCopyOrMove, which removes the requirement
for explicit copy or move special member functions when they are already
implicitly deleted.

Closes #62392
2024-05-15 17:53:03 +02:00
Julian Schmidt
3b5a121a24
[clang-tidy][NFC] replace comparison of begin and end iterators with range empty (#91994)
Improves readability by changing comparisons of `*_begin` and `*_end`
iterators into `.empty()` on their range.
2024-05-15 14:35:07 +02:00
Timm Baeder
3d56ea05b6
[clang][NFC] Fix FieldDecl::isUnnamedBitfield() capitalization (#89048)
We always capitalize bitfield as "BitField".
2024-04-18 07:39:29 +02:00
Danny Mösch
16b3e43a03
[clang-tidy] Ignore non-forwarded arguments if they are unused (#87832) 2024-04-08 23:54:29 +02:00
Piotr Zegar
11a411a49b Revert "[clang-tidy][NFC] Remove duplicated code"
This reverts commit b6f6be4b500ff64c23a5103ac3311cb74519542f.
2024-03-31 15:06:49 +00:00
Piotr Zegar
b6f6be4b50 [clang-tidy][NFC] Remove duplicated code
Remove duplicated matchers by moving some of them to
utils/Matchers.h. Add some anonymous namespaces and
renamed some code to avoid ODR issues.
2024-03-31 14:58:27 +00: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
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
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
Congcong Cai
e9cec39239
[clang-tidy] fix incorrect hint for InitListExpr in prefer-member-initializer (#81560) 2024-02-16 09:18:21 +08: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
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
Qizhi Hu
d08482924e
[clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (#77056)
Parameter variable which is forwarded in lambda capture list or in body
by reference is reasonable and current version of this check produces
false positive on these cases. This patch try to fix the
[issue](https://github.com/llvm/llvm-project/issues/68105)

Co-authored-by: huqizhi <836744285@qq.com>
2024-01-06 19:50:00 +08:00
Congcong Cai
43e13fdc9e
[NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (#71006) 2023-11-02 19:30:06 +08:00
Congcong Cai
263746754a
[clang-tidy]Fix PreferMemberInitializer false positive for reassignment (#70316)
- assignment twice cannot be simplified to once when assigning to
reference type
- safe assignment cannot be advanced before unsafe assignment
2023-10-27 23:56:25 +08:00
Piotr Zegar
c02b2ab8ab
[clang-tidy] Add StrictMode to cppcoreguidelines-pro-type-static-cast-downcast (#69529)
Add StrictMode option that controls behavior whatever
warnings are emitted for casts on non-polymorphic types.

Fixes: #69414
2023-10-26 21:06:19 +02:00
Congcong Cai
f5063bf7ed [clang-tidy][NFC]refactor PreferMemberInitializerCheck for readability 2023-10-26 13:37:50 +08:00
Piotr Zegar
fd06155acb
[clang-tidy] Improved cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes (#69242)
Extended IgnoreConversionFromTypes option to include
types without a declaration, such as built-in types.
2023-10-26 07:16:25 +02:00
Piotr Zegar
af07d7ba88
[clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (#69501)
Improved cppcoreguidelines-pro-type-const-cast check to ignore casts to
const type (controlled by option) and casts in implicitly invoked code.

Fixes #69319
2023-10-26 07:11:01 +02:00
Piotr Zegar
20d210285b
[clang-tidy] Ignore deleted functions in cppcoreguidelines-rvalue-reference-param-not-moved (#69514)
Ignore functions and constructors that are maked deleted or defaulted in
cppcoreguidelines-rvalue-reference-param-not-moved check.

Fixes #69412
2023-10-25 20:41:19 +02:00
AMS21
bb6a98c8d2
[clang-tidy] Ignore unused parameters in rvalue-reference-param-not-moved check (#69045)
With this patch we no longer issue a warning for unused parameters which
are marked as such.

This fixes #68209
2023-10-14 22:51:50 +02:00
Piotr Zegar
cbdc3e1bf9 [clang-tidy][NFC] Fix cppcoreguidelines-init-variables findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 11:59:03 +00:00
Piotr Zegar
26078f33bd [clang-tidy][NFC] Fix cppcoreguidelines-missing-std-forward findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 11:59:03 +00:00
Piotr Zegar
01c8bf6fd4 [clang-tidy][NFC] Fix llvm-else-after-return findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 11:59:02 +00:00
Piotr Zegar
fc2a9ad10e [clang-tidy][NFC] Fix modernize-use-auto findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 11:59:02 +00:00
Piotr Zegar
24a7587b79 [clang-tidy][NFC] Fix readability-make-member-function-const findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 08:52:11 +00:00
Piotr Zegar
ec5f4be452 [clang-tidy][NFC] Fix modernize-return-braced-init-list findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 08:52:10 +00:00
Piotr Zegar
c5a4f29ef0 [clang-tidy][NFC] Fix readability-container-size-empty findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 08:52:10 +00:00
Piotr Zegar
f1f16331bd [clang-tidy][NFC] Fix readability-inconsistent-declaration-parameter-name findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 08:52:09 +00:00
Jorge Pinto Sousa
41818ce150 [clang-tidy] Access checks not done classes derived of std::array
Index accessing checks are not performed for derived classes of
of `std::array`, as only `std::array` itself and its aliases
seems to be checked.

This patch aims to extend it for derived classes such as:
```
template<class T, size_t N>
class DerivedArray : public std::array<T, N> {};
```

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D156624
2023-08-25 17:09:04 +00:00