Commit Graph

1180 Commits

Author SHA1 Message Date
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
Jonas Toth 46ae26e7eb [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables
This patch connects the check for const-correctness with the new general
utility to add `const` to variables.
The code-transformation is only done, if the detected variable for const-ness
is not part of a group-declaration.

The check allows to control multiple facets of adding `const`, e.g. if pointers themself should be
marked as `const` if they are not changed.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D54943
2022-07-24 19:37:54 +02:00
Fangrui Song 52cb972537 [CommandLine] --help: print "-o <xxx>" instead of "-o=<xxx>"
Accepting -o= is a quirk of CommandLine. For --help, we should print the
conventional "-o <xxx>".
2022-07-14 01:28:28 -07:00
Balázs Kéri 0e95921bc3 [clang-tidy] Improve check cert-dcl58-cpp.
Detect template specializations that should be handled specially.
In some cases it is allowed to extend the `std` namespace with
template specializations.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129353
2022-07-14 09:04:03 +02:00
Danny Mösch 963192228b [clang-tidy] Sort release notes entries alphabetically by check name 2022-07-09 15:45:19 +02:00
Danny Mösch 33e2129544 [clang-tidy] Initialize boolean variables with `false` in cppcoreguidelines-init-variables' fix-it
In case of a variable with a built-in boolean type, `false` is a better fit to default-initialize it.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D129420
2022-07-09 14:48:50 +02:00
Dmitri Gribenko 40af95d80b [clang-tools-extra] Fix a link in ReleaseNotes.rst 2022-07-05 23:09:55 +02:00
Dmitri Gribenko 05130a6ba7 new clang-tidy checker for assignments within condition clause of if statement
new clang-tidy checker for assignments within the condition clause of an 'if' statement.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D127114
2022-07-05 23:04:12 +02:00
Ishaan Gandhi a65a3bffd3 [clang-tidy] Don't treat invalid branches as identical
The clang-tidy check bugprone-branch-clone has a false positive if some
symbols are undefined. This patch silences the warning when the two
sides of a branch are invalid.

Fixes #56057

Differential Revision: https://reviews.llvm.org/D128402
2022-07-03 15:50:33 -06:00
Richard 5e97788a3e [clang-tidy] Update release notes (NFC)
- Sort changes to existing checks by check name
- Correct check link
2022-06-24 10:48:47 -06:00
Nathan James fbf611ed2a
[clang-tidy] Extend spelling for CheckOptions
The current way to specify CheckOptions is pretty verbose and unintuitive.
Given that the options are a dictionary it makes much more sense to treat them as such in the config files.
Example:
```
CheckOptions: {SomeCheck.Option: true, SomeCheck.OtherOption: 'ignore'}
# Or
CheckOptions:
  SomeCheck.Option: true
  SomeCheck.OtherOption: 'ignore'
```

This change will still handle the old syntax with no issue, ensuring we don't screw up users current config files.

The only observable differences are support for the new syntax and `-dump=config` will emit using the new syntax.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D128337
2022-06-23 19:59:31 +01:00
Nathan James 5ca68d5845
[clang-tidy] Add `-verify-config` command line argument
Adds a `-verify-config` command line argument, that when specified will verify the Checks and CheckOptions fields in the config files:
 - A warning will be raised for any check that doesn't correspond to a registered check, a suggestion will also be emitted for close misses.
 - A warning will be raised for any check glob(containing *) that doesn't match any registered check.
 - A warning will be raised for any CheckOption that isn't read by any registered check, a suggestion will also be emitted for close misses.

This can be useful if debuging why a certain check isn't enabled, or the options are being handled as you expect them to be.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D127446
2022-06-23 19:23:09 +01:00
Aaron Ballman e36535f99c Fix sphinx build for clang-tools-extra
I think it doesn't like the non-ASCII characters in the block, so using
a text block to disable syntax highlighting.

This should fix:
https://lab.llvm.org/buildbot/#/builders/115/builds/29888
2022-06-23 07:22:00 -04:00
Nathan James b1cc59fd3a
[clang-tidy][docs] Reorganise release notes 2022-06-22 21:21:24 +01:00
Richard 89a1d03e2b [clang-tidy] Organize test files into subdirectories by module (NFC)
Eliminate clutter by reorganizing the Lit test files for clang-tidy:
- Move checkers/<module>-* to checkers/<module>/*.
- Move module specific inputs from Inputs to <module>/Inputs.  Remove
  any module prefix from the file or subdirectory name as they are no
  longer needed.
- Introduce a Lit substitution %clang_tidy_headers for the system
  headers in checkers/Inputs/Headers and use this throughout.  This
  avoids referencing system headers through a relative path to the
  parent directory and makes it clear that these fake system headers are
  shared among all modules.
- Update add_new_check.py to follow the above conventions when creating
  the boiler plate test files for a new check.
- Update Contributing.rst to describe per-module Inputs directory and
  fix link to test source code.

Differential Revision: https://reviews.llvm.org/D128072
2022-06-22 12:13:34 -06:00
Richard b967a97550 [clang-tidy] Fix documentation (NFC)
The documentation files were reorganized into subdirectories, but a new
check was added concurrently and wasn't rebased correctly before
submitting.  Sort the new clang-tidy checks by check name and fix the
indentation of bugprone-unchecked-optional-access.
2022-06-22 10:49:00 -06:00
serge-sans-paille c3574ef739 [clang-tidy] Confusable identifiers detection
Detect identifiers that are confusable using a variant of Unicode definition

        http://www.unicode.org/reports/tr39/#Confusable_Detection

and have conflicting scopes.

This a recommit (with portability and feature fixes) of b94db7ed7e

Differential Revision: https://reviews.llvm.org/D112916
2022-06-22 16:17:20 +02:00
Aaron Ballman bb297024fa Don't treat invalid parameters as being unused
The misc-unused-parameters check would trigger false positive warnings
about the parameter being unused when the parameter declaration was
invalid. No longer issue the warning in that case on the assumption
that most parameters are used in practice, so the extra diagnostic is
most likely a false positive.

Fixes #56152
2022-06-22 08:56:38 -04:00
Balazs Benics ae76b2f455 [clang-tidy][docs] Fix wrong sphinx link after d9afb8c3e8
There was a copy-paste mistake at the embedded link:
  `clang-tidy/checks/cppcoreguidelines-virtual-class-destructor`
  ->
  `clang-tidy/checks/cppcoreguidelines/virtual-class-destructor`

Sphinx error:
/home/zbebnal/git/llvm-project/clang-tools-extra/docs/ReleaseNotes.rst:168:unknown document: clang-tidy/checks/cppcoreguidelines-virtual-class-destructor

Build bot: https://lab.llvm.org/buildbot#builders/115/builds/29805

Differential Revision: https://reviews.llvm.org/D126891
2022-06-21 11:42:09 +02:00