Commit Graph

1198 Commits

Author SHA1 Message Date
Kazu Hirata
f71ffd3b73 [clang-tools-extra] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to clean up the "using" declarations, #include
"llvm/ADT/Optional.h", etc.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 20:19:42 -08:00
Chris Cotter
210b731c01 [clang-tidy] Fix minor bug in add_new_check.py
While rebuilding the list of checks in add_new_check.py,
check is a file is a subdirectory before traversing it.

Test plan: Ran `./add_new_check.py --update-docs` and confirmed the list.rst file was unchanged.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D140772
2023-01-05 15:28:57 +00:00
Chris Cotter
b06b248ad9 [clang-tidy] Implement CppCoreGuideline CP.53
Implement CppCoreGuideline CP.53 to warn when a coroutine accepts
references parameters. Although the guideline mentions that it is safe
to access a reference parameter before suspension points, the guideline
recommends flagging all coroutine parameter references.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D140793
2023-01-05 13:57:22 +00:00
Haojian Wu
0e11d65a58 [clang-tidy] Don't emit misc-unused-using-decl warnings for header files.
Using decls in header files are special, usually as part of the
public API, the check should not emit warnings on these.

The check already detects unused using-decls which are in the current main
file, but if the main file happens to be a header file, we still
emit warnings, this patch suppresses that.

Differential Revision: https://reviews.llvm.org/D140894
2023-01-04 10:07:28 +01:00
Tamas Berghammer
f325b5b8cb [clang-tidy] Support std::string_view in readability-redundant-string-cstr
Previously we were matching constructor calls for std::string and
llvm::StringRef and this change extends this set with including
std::string_view as well.

Reviewed By: njames93, carlosgalvezp

Differential Revision: https://reviews.llvm.org/D140018
2023-01-02 06:24:00 -05:00
Carlos Galvez
66bf54abb5 [clang-tidy] Use Python3 for add_new_check.py and rename_check.py
Fixes #58782

Differential Revision: https://reviews.llvm.org/D139966
2022-12-16 06:54:16 +00:00
Carlos Galvez
35d9f873e3 [clang-tidy] Fix a couple additional cases in misc-use-anonymous-namespace only
- Do not analyze header files, since we don't want to promote
  using anonymous namespaces there.

- Do not warn about const/constexpr variables, those are implicitly
  static in C++ and they don't need to be moved to an anonymous
  namespace. Warning about redundant static in general could be
  implemented as a standalone check, moving away some of the
  functionality from this check.

This check has been introduced in the current release, thus
no mention of this change is needed in the Release Notes.

Differential Revision: https://reviews.llvm.org/D139113
2022-12-12 15:26:14 +00:00
Abraham Corea Diaz
ec3f8feddf [Clang-Tidy] Empty Check
Adds a clang-tidy check for the incorrect use of `empty()` on a
container when the result of the call is ignored.

Authored-by: Abraham Corea Diaz <abrahamcd@google.com>
Co-authored-by: Denis Nikitin <denik@google.com>

Reviewed By: cjdb

Differential Revision: https://reviews.llvm.org/D128372
2022-12-09 23:19:45 +00:00
Carlos Galvez
7fd8387917 [clang-tidy] Do not warn about redundant static in misc-use-anonymous-namespace
The same functionality is already implemented in the
readability-static-definition-in-anonymous-namespace
check, including automatic fixes.

Differential Revision: https://reviews.llvm.org/D139197
2022-12-08 11:40:50 +00:00
Carlos Galvez
65d6d67fc9 [clang-tidy] Add misc-use-anonymous-namespace check
Differential Revision: https://reviews.llvm.org/D137340
2022-12-01 07:19:30 +00:00
Stephane Moore
6c2140943c [clang-tidy] Suppress google-objc-avoid-throwing-exception in system macros 🫢
The google-objc-avoid-throwing-exception check enforces the Google
Objective-C Style Guide's prohibition on throwing exceptions in user
code but the check incorrectly triggers findings for code emitted from
system headers. This commit suppresses any findings that do not have
valid locations or are emitted from macros in system headers.

Avoid Throwing Exceptions, Google Objective-C Style Guide:
https://github.com/google/styleguide/blob/gh-pages/objcguide.md#avoid-throwing-exceptions

Test Notes:
Ran clang-tidy lit tests.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D137738
2022-11-30 16:44:45 -08:00
Raul Ferrando
b24d89a042 Update wrong Unicode code point in confusable-identifiers.rst
In confusable-identifiers.rst the description refers to wrong Unicode code point.

The shown code point is U+1D41F, not U+1234.
Updated the code point and it's description.

Fixes #58934

Differential Revision: https://reviews.llvm.org/D138838
2022-11-28 15:32:40 -05:00
Thomas Etter
a49fcca9e3 [clang-tidy] Optionally ignore findings in macros in readability-const-return-type.
Adds support for options-controlled configuration of the check to ignore results in macros.

Differential Revision: https://reviews.llvm.org/D137972
2022-11-15 14:28:03 +00:00
Thomas Etter
f3afd16b65 [clang-tidy] Ignore overriden methods in readability-const-return-type.
Overrides are constrained by the signature of the overridden method, so a
warning on an override is frequently unactionable.

Differential Revision: https://reviews.llvm.org/D137968
2022-11-15 14:24:05 +00:00
Alexander Shaposhnikov
29e4606ced [clang-tidy] Skip template ctors in modernize-use-equals-default
Skip template ctors in modernize-use-equals-default,
such constructors may be enabled/disabled via SFINAE,
it is not safe to make them "= default".

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D136797
2022-10-28 05:30:19 +00:00
Alexander Shaposhnikov
6c07bda7a7 [clang-tidy] Avoid adding unnecessary semicolon in modernize-use-equals-default
Adjust the automatic fixit to avoid adding superfluous semicolon.

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D136399
2022-10-22 00:42:50 +00:00
Sylvestre Ledru
b814d85e5b Update links to googletest documentation
Update links to googletest documentation
No automatic tests, but local manual test: i click it, it opens the googletest documentation.

Reviewed By: sylvestre.ledru

Differential Revision: https://reviews.llvm.org/D136424
2022-10-21 13:55:44 +02:00
Alexander Shaposhnikov
90d42b1cab [clang-tidy] Skip private default ctors in modernize-use-equals-default
For c++17 (i.e. before c++20) making a private default ctor explicitly defaulted
might expose the previously intentionally disallowed initializations, e.g.
class Tag { Tag() {} friend class Widget; }; is not equivalent to
class Tag { Tag() = default; friend class Widget; };
since in the latter case Tag is treated as an aggregate despite having a declaration
of the default constructor. This diff makes modernize-use-equals-default skip
in-class empty nonpublic default ctors to avoid code breakages.

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D136224
2022-10-20 22:04:33 +00:00
Aaron Ballman
71b4bc185f Fix clang-tools-extra Sphinx build
This should address the issues found in:
https://lab.llvm.org/buildbot/#/builders/115/builds/35504
2022-10-10 07:55:26 -04:00
Carlos Galvez
1ae33bf426 [clang-tidy] Add cppcoreguidelines-avoid-do-while check
Implements rule ES.75 of C++ Core Guidelines.

Differential Revision: https://reviews.llvm.org/D132461
2022-10-10 07:29:17 +00:00
Evgeny Shulgin
a8fbd1157d [clang-tidy] Ignore concepts in misc-redundant-expression
The checker should ignore requirement expressions inside concept
definitions, because redundant expressions still make sense here

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

Reviewed By: njames93, aaron.ballman

Differential Revision: https://reviews.llvm.org/D122078
2022-10-08 10:37:16 +00:00
Emilia Dreamer
2d149d17f0 [clang-tidy] Fix crashes on if consteval in readability checks
The `readability-braces-around-statements` check tries to look at the
closing parens of the if condition to determine where to insert braces,
however, "consteval if" statements don't have a condition, and always
have braces regardless, so the skip can be checked.

The `readability-simplify-boolean-expr` check looks at the condition
of the if statement to determine what could be simplified, but as
"consteval if" statements do not have a condition that could be
simplified, they can also be skipped here.

There may still be more checks that try to look at the conditions of
`if`s that aren't included here

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

Reviewed By: njames93, aaron.ballman

Differential Revision: https://reviews.llvm.org/D133413
2022-10-05 09:38:05 +03:00
Balázs Kéri
6d9eb53329 [clang-tidy] Add checker 'bugprone-suspicious-realloc-usage'.
Add a check to detect usages of `realloc` where the result is assigned
to the same variable (or field) as passed to the first argument.

Reviewed By: steakhal, martong

Differential Revision: https://reviews.llvm.org/D133119
2022-10-04 09:14:46 +02:00
Alexander Shaposhnikov
d4e81097ea [clang-tidy] Skip variadic ctors in modernize-use-equals-default
Skip variadic constructors in modernize-use-equals-default
(such constructors cannot be explicitly defaulted).

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D134929
2022-09-30 22:16:28 +00:00
Yitzhak Mandelbaum
40f5c634bc [NFC] Fix for doc typo in commit 9a4e52ebeb 2022-09-30 14:53:18 +00:00
Yitzhak Mandelbaum
9a4e52ebeb [clang-tidy] Add an IgnoreMacros option to readability-avoid-const-params-in-decls
readability-avoid-const-params-in-decls.IgnoreMacros is enabled by default to be consistent with most other checks.

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D130130
2022-09-30 14:27:02 +00:00
Michael Benfield
33bc9c3bf2 Document WarnOnSizeOfPointerToAggregate.
This option was just landed in D134381. It would make sense to actually
document it.

Differential Revision: https://reviews.llvm.org/D134457
2022-09-22 17:38:04 +00:00
Alexander Shaposhnikov
44503482e0 [clang-tidy] Skip union-like classes in use-equals-default
Skip unions/union-like classes since in this case constructors
with empty bodies behave differently in comparison with regular
structs/classes.

Test plan: ninja check-clang-tools

Differential revision: https://reviews.llvm.org/D132713
2022-09-06 20:19:47 +00:00
Alexander Shaposhnikov
a7395b860b [clang-tidy] Skip copy assignment operators with nonstandard return types
Skip copy assignment operators with nonstandard return types
since they cannot be defaulted.

Test plan: ninja check-clang-tools

Differential revision: https://reviews.llvm.org/D133006
2022-09-02 22:43:39 +00:00
Alexander Shaposhnikov
47dbacbc8a [clang-tidy] Restrict use-equals-default to c++11-or-later
Restrict use-equals-default to c++11-or-later.

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D132998
2022-09-02 22:19:11 +00:00
Nathan James
cc09b81265 [CTE][docs] Fix bad links in ReleaseNotes 2022-09-01 12:10:53 +01:00
corona10
495d984e14 [clang-tidy] Fix modernize-use-emplace to support alias cases
Fix modernize-use-emplace to support alias cases

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D132640
2022-08-31 10:21:10 +01:00
Jonas Toth
b5b7503463 [docs] improve documentation for misc-const-correctness
Improve the documentation for 'misc-const-correctness' to:

- include better examples
- improve the english
- fix links to other checks that were broken due to the directory-layout changes
- mention the limitation that the check does not run on `C` code.

Addresses #56749, #56958

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D132244
2022-08-29 11:20:47 +02:00
Nathan James
6bd98b4f2d [clang-tidy] Fix a false positive in bugprone-assignment-in-if-condition
Fixed a false positive where a lambda expression in the condition which contained an assignement would trigger a warning.
Fixes #56729

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D132786
2022-08-27 19:55:08 +01:00
Sockke
2d8e91a5d3 [clang-tidy] Ignore other members in a union if any member of it is initialized in cppcoreguidelines-pro-type-member-init
If a union member is initialized, the other members of the union are still suggested to be initialized in this check.  This patch fixes this behavior.
Reference issue: https://github.com/llvm/llvm-project/issues/54748

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D127293
2022-08-25 18:47:38 +08:00
Alexander Shaposhnikov
083e3a173d [clang-tidy] Skip unions in use-equals-default
For unions constructors with empty bodies behave differently
(in comparison with structs/classes) and clang-tidy's fix
might break the code. This diff adjusts the check to skip unions
for now (it seems to be a relatively rare case).

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D132290
2022-08-23 20:09:47 +00:00
Joey Watts
b8655f7ff2 [clang-tidy] Improve modernize-use-emplace check
This patch improves the modernize-use-emplace check by adding support for
detecting inefficient invocations of the `push` and `push_front` methods on
STL-style containers and replacing them with their `emplace`-style equivalent.

Fixes #56996.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D131623
2022-08-19 07:57:42 +01:00
Balázs Kéri
6e75ec5e38 [clang-tidy] Support C++14 in bugprone-signal-handler.
Check `bugprone-signal-handler` is improved to check for
C++-specific constructs in signal handlers. This check is
valid until C++17.

Reviewed By: whisperity

Differential Revision: https://reviews.llvm.org/D118996
2022-08-12 09:45:53 +02:00
Vladimir Plyashkun
6c7b049f6e [clang-tidy][docs] Fixed page title for abseil-no-internal-dependencies check documentation
It seems that documentation for abseil-no-internal-dependencies has invalid title.
This can be checked by looking at the actual web-site - https://clang.llvm.org/extra/clang-tidy/checks/abseil/no-internal-dependencies.html
There is redundant "subl.. title:: clang-tidy - abseil-no-internal-dependencies" paragraph in the beginning.

Reviewed By: njames93, sylvestre.ledru

Differential Revision: https://reviews.llvm.org/D131590
2022-08-11 21:09:39 +01:00
Carlos Galvez
9ae5896d96 [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check
Flags uses of const-qualified and reference data members in structs.
Implements rule C.12 of C++ Core Guidelines.

Differential Revision: https://reviews.llvm.org/D126880
2022-08-11 07:46:04 +00:00
Simon Pilgrim
25340410c9 Revert rGa772f775a2ba401e95a0bbe73deb6300f1dc12c0 "[clang-tidy] Support C++14 in bugprone-signal-handler."
This was breaking a number of buildbots: https://lab.llvm.org/buildbot/#/builders/139/builds/26335
2022-08-10 15:25:04 +01:00
Balázs Kéri
a772f775a2 [clang-tidy] Support C++14 in bugprone-signal-handler.
Check `bugprone-signal-handler` is improved to check for
C++-specific constructs in signal handlers. This check is
valid until C++17.

Reviewed By: whisperity

Differential Revision: https://reviews.llvm.org/D118996
2022-08-10 12:00:16 +02:00
Rashmi Mudduluru
13bc713109 fixes clang-tidy/checks/list.rst: a line was accidentally removed in 95a92995d4 2022-08-05 12:36:03 -07:00
Petr Hosek
ea50901aa9 [clang-doc] Default to Standalone executor and improve documentation
This should provide a more intuitive usage consistent with other tools.

Differential Revision: https://reviews.llvm.org/D130226
2022-08-04 17:43:16 +00:00
Rashmi Mudduluru
95a92995d4 Adds the NSDateFormatter checker to clang-tidy
Differential Revision: https://reviews.llvm.org/D126097
2022-08-02 13:57:44 -07:00
Sylvestre Ledru
556c422de1 clang-tidy doc: fix some typos 2022-08-01 18:57:36 +02:00
Sylvestre Ledru
37047a2673 misc-const-correctness: fix the link to readability-isolate-declaration 2022-08-01 18:52:53 +02:00
Tom Stellard
809855b56f Bump the trunk major version to 16 2022-07-26 21:34:45 -07:00
Danny Mösch
0734c02b34 [clang-tidy] Avoid extra parentheses around MemberExpr
Fixes https://github.com/llvm/llvm-project/issues/55025.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129596
2022-07-26 22:36:00 +02:00
Danny Mösch
4e94f66531 [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads
Without the "found declaration" it is later not possible to know where the operator declaration
was brought into the scope calling it.

The initial motivation for this fix came from #55095. However, this also has an influence on
`clang -ast-dump` which now prints a `UsingShadow` attribute for operators only visible through
`using` statements. Also, clangd now correctly references the `using` statement instead of the
operator directly.

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D129973
2022-07-26 21:22:18 +02:00