[clang-tools-extra] [clang-tidy] Add `bugprone-virtual-arithmetic` check (PR #91951)

2024-05-13 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

I realize it's probably very hard (if not impossible) to detect whether a class 
is a base class unless it has virtual functions. 

That's why the corresponding AUTOSAR rule bans only non-final classes. But that 
is a bit overkill and leads to some pain.



https://github.com/llvm/llvm-project/pull/91951
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add `bugprone-virtual-arithmetic` check (PR #91951)

2024-05-13 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Otherwise since this is a problem also on non-polymorphic objects, maybe 
"bugprone-pointer-arithmetic-base-class"?

https://github.com/llvm/llvm-project/pull/91951
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add `bugprone-virtual-arithmetic` check (PR #91951)

2024-05-13 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

I'm not very happy about the name, there's no such thing as "virtual 
arithmetic".

What about "bugprone-pointer-arithmetic-polymorphic-object"?

I rather have a long descriptive name than a short ambiguous name.

https://github.com/llvm/llvm-project/pull/91951
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add `modernize-use-uniform-initializer` check (PR #91124)

2024-05-05 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Consider also that this check should probably not apply to variables of type 
`auto`, see AUTOSAR rule A8-5-3.

https://github.com/llvm/llvm-project/pull/91124
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add `modernize-use-uniform-initializer` check (PR #91124)

2024-05-05 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Regarding the problem of {} initialization and std::vector, I believe we could 
restrict this check to not warn on classes that have a constructor taking a 
`std:: initializer_list`. I believe AUTOSAR has an exception for that.

https://github.com/llvm/llvm-project/pull/91124
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] new check readability-mark-static (PR #90830)

2024-05-04 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

> Should I implement auto-fix for this check?

As a first step we can have it without auto-fix and add that as a second step 
once we figure out a good way to do it.

https://github.com/llvm/llvm-project/pull/90830
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] new check readability-mark-static (PR #90830)

2024-05-02 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

- I'm not sure this is so much a readability check, I'd put it in `misc`. The 
main problem that it solves is avoiding ODR violations. I'd call it 
`misc-prefer-internal-linkage`.
 
- The auto-fix should be configurable to choose `static` or anonymous namespace.


https://github.com/llvm/llvm-project/pull/90830
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() (PR #90043)

2024-04-25 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Please note: the guidelines do not require one to replace [] with at(), that's 
just one of the possible solutions. Actually at() is banned in many codebases 
where exceptions are banned.

It would be good to make this fix-it opt-in,  configurable via option, so the 
check only emits a warning by default.

https://github.com/llvm/llvm-project/pull/90043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)

2024-04-10 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Great! Nothing else from my side

https://github.com/llvm/llvm-project/pull/87792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)

2024-04-09 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Nice! Should we add this example as a test case?

https://github.com/llvm/llvm-project/pull/87792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)

2024-04-08 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

> the user may not have the ability to change the definition of the macro to be 
> able to appease the check

My understanding of this PR is that the user would only need to change what 
they pass into the macro, not the macro itself, or? E.g.

```cpp
-MY_MACRO(foo)
+MY_MACRO(g_foo)
```

https://github.com/llvm/llvm-project/pull/87792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Remove unnecessary nullptr check on cast subexpr (PR #85473)

2024-03-16 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Shouldn't we simply `return`?

As you say, the assert is disabled in Release mode. Even if it's enabled, the 
author if `getSubExpr` may one day decide to remove the assert without possibly 
knowing all the places that do rely on that assert, leaving the code 
unprotected. It seems like it's trivial solution to `return` and be on the safe 
side.

https://github.com/llvm/llvm-project/pull/85473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [run-clang-tidy.py] Add option to ignore source files from compilation database (PR #82416)

2024-02-21 Thread Carlos Galvez via cfe-commits


@@ -97,6 +97,9 @@ The improvements are...
 Improvements to clang-tidy
 --
 
+- Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
+  to filter out source files from the compilation database.

carlosgalvezp wrote:

I read this as "the option 'source-filter' is used to filter out source files". 
But in reality it's doing the opposite: it will filter **in** those source 
files (just like header-filter).

Maybe we can write something like "with the same semantics of header-filter, 
but for source files"?

https://github.com/llvm/llvm-project/pull/82416
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [run-clang-tidy.py] Add option to ignore source files from compilation database (PR #82416)

2024-02-20 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

> Why "ignore" instead of "filter"?

Why can't we make "filter" use a full regex that supports negative expressions 
instead?


https://github.com/llvm/llvm-project/pull/82416
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

This problem seems like it should be handled globally, not in a single specific 
check. IIUC any check that reads options from the .cñsng-tidy file is affected.

What build system are you using, bazel? We use it and don't have any problems. 
If your build system creates a sandbox, you need to make sure clang-tidy is 
also executed from within that sandbox.

https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-02 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp closed 
https://github.com/llvm/llvm-project/pull/80333
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/80333

>From b40347c8025b0d5de83453012a76d412c07f54a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Thu, 1 Feb 2024 20:00:45 +
Subject: [PATCH 1/2] [clang-tidy] Remove check-specific HeaderFileExtensions
 and ImplementationFileExtensions

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

Fixes #61947
---
 .../DynamicStaticInitializersCheck.cpp| 22 +--
 .../bugprone/DynamicStaticInitializersCheck.h | 10 -
 .../bugprone/SuspiciousIncludeCheck.cpp   | 38 ++
 .../bugprone/SuspiciousIncludeCheck.h | 15 ---
 .../google/GlobalNamesInHeadersCheck.cpp  | 22 +--
 .../google/GlobalNamesInHeadersCheck.h| 10 -
 .../google/UnnamedNamespaceInHeaderCheck.cpp  | 22 +--
 .../google/UnnamedNamespaceInHeaderCheck.h| 10 -
 .../misc/DefinitionsInHeadersCheck.cpp| 39 +++
 .../misc/DefinitionsInHeadersCheck.h  |  9 -
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 17 +---
 .../misc/UseAnonymousNamespaceCheck.cpp   | 22 +--
 .../misc/UseAnonymousNamespaceCheck.h | 10 -
 .../clang-tidy/utils/HeaderGuard.cpp  |  4 --
 .../clang-tidy/utils/HeaderGuard.h| 27 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   | 31 +++
 .../checks/bugprone/suspicious-include.rst| 24 
 .../checks/google/build-namespaces.rst| 15 ---
 .../checks/google/global-names-in-headers.rst | 15 ---
 .../clang-tidy/checks/llvm/header-guard.rst   | 15 ---
 .../checks/misc/definitions-in-headers.rst| 24 
 .../checks/misc/unused-using-decls.rst| 16 +---
 .../checks/misc/use-anonymous-namespace.rst   | 16 +---
 23 files changed, 54 insertions(+), 379 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4a467120181b4..93f35cb2c1a3d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -27,26 +27,8 @@ AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
 
 DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context) {
-  std::optional HeaderFileExtensionsOption =
-  Options.get("HeaderFileExtensions");
-  RawStringHeaderFileExtensions =
-  
HeaderFileExtensionsOption.value_or(utils::defaultHeaderFileExtensions());
-  if (HeaderFileExtensionsOption) {
-if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-HeaderFileExtensions,
-utils::defaultFileExtensionDelimiters())) {
-  this->configurationDiag("Invalid header file extension: '%0'")
-  << RawStringHeaderFileExtensions;
-}
-  } else
-HeaderFileExtensions = Context->getHeaderFileExtensions();
-}
-
-void DynamicStaticInitializersCheck::storeOptions(
-ClangTidyOptions::OptionMap ) {
-  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
-}
+: ClangTidyCheck(Name, Context),
+  HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index d8ac31dc3b850..66ed2828502b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -15,26 +15,16 @@
 namespace clang::tidy::bugprone {
 
 /// Finds dynamically initialized static variables in header files.
-///
-/// The check supports these options:
-///   - `HeaderFileExtensions`: a semicolon-separated list of filename
-/// extensions of header files (The filename extensions should not contain
-/// "." prefix). ";h;hh;hpp;hxx" by default.
-//
-/// For extension-less header files, using an empty string or leaving an
-/// empty string between ";" if there are other filename extensions.
 class DynamicStaticInitializersCheck : public ClangTidyCheck {
 public:
   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions ) const override {
 return LangOpts.CPlusPlus && !LangOpts.ThreadsafeStatics;
   }
-  void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 
 

[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-prefer-member-init (PR #80330)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp closed 
https://github.com/llvm/llvm-project/pull/80330
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/80333

>From fbb0837342a566ff928b211cbb418075a7e744fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Thu, 1 Feb 2024 20:00:45 +
Subject: [PATCH 1/2] [clang-tidy] Remove check-specific HeaderFileExtensions
 and ImplementationFileExtensions

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

Fixes #61947
---
 .../DynamicStaticInitializersCheck.cpp| 22 +--
 .../bugprone/DynamicStaticInitializersCheck.h | 10 -
 .../bugprone/SuspiciousIncludeCheck.cpp   | 38 ++
 .../bugprone/SuspiciousIncludeCheck.h | 15 ---
 .../google/GlobalNamesInHeadersCheck.cpp  | 22 +--
 .../google/GlobalNamesInHeadersCheck.h| 10 -
 .../google/UnnamedNamespaceInHeaderCheck.cpp  | 22 +--
 .../google/UnnamedNamespaceInHeaderCheck.h| 10 -
 .../misc/DefinitionsInHeadersCheck.cpp| 39 +++
 .../misc/DefinitionsInHeadersCheck.h  |  9 -
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 17 +---
 .../misc/UseAnonymousNamespaceCheck.cpp   | 22 +--
 .../misc/UseAnonymousNamespaceCheck.h | 10 -
 .../clang-tidy/utils/HeaderGuard.cpp  |  4 --
 .../clang-tidy/utils/HeaderGuard.h| 27 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   | 31 +++
 .../checks/bugprone/suspicious-include.rst| 24 
 .../checks/google/build-namespaces.rst| 15 ---
 .../checks/google/global-names-in-headers.rst | 15 ---
 .../clang-tidy/checks/llvm/header-guard.rst   | 15 ---
 .../checks/misc/definitions-in-headers.rst| 24 
 .../checks/misc/unused-using-decls.rst| 16 +---
 .../checks/misc/use-anonymous-namespace.rst   | 16 +---
 23 files changed, 54 insertions(+), 379 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4a467120181b4..93f35cb2c1a3d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -27,26 +27,8 @@ AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
 
 DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context) {
-  std::optional HeaderFileExtensionsOption =
-  Options.get("HeaderFileExtensions");
-  RawStringHeaderFileExtensions =
-  
HeaderFileExtensionsOption.value_or(utils::defaultHeaderFileExtensions());
-  if (HeaderFileExtensionsOption) {
-if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-HeaderFileExtensions,
-utils::defaultFileExtensionDelimiters())) {
-  this->configurationDiag("Invalid header file extension: '%0'")
-  << RawStringHeaderFileExtensions;
-}
-  } else
-HeaderFileExtensions = Context->getHeaderFileExtensions();
-}
-
-void DynamicStaticInitializersCheck::storeOptions(
-ClangTidyOptions::OptionMap ) {
-  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
-}
+: ClangTidyCheck(Name, Context),
+  HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index d8ac31dc3b850..66ed2828502b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -15,26 +15,16 @@
 namespace clang::tidy::bugprone {
 
 /// Finds dynamically initialized static variables in header files.
-///
-/// The check supports these options:
-///   - `HeaderFileExtensions`: a semicolon-separated list of filename
-/// extensions of header files (The filename extensions should not contain
-/// "." prefix). ";h;hh;hpp;hxx" by default.
-//
-/// For extension-less header files, using an empty string or leaving an
-/// empty string between ";" if there are other filename extensions.
 class DynamicStaticInitializersCheck : public ClangTidyCheck {
 public:
   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions ) const override {
 return LangOpts.CPlusPlus && !LangOpts.ThreadsafeStatics;
   }
-  void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 
 

[clang-tools-extra] [clang-tidy] Remove check-specific HeaderFileExtensions and Implement… (PR #80333)

2024-02-01 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/80333

…ationFileExtensions

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

Fixes #61947

>From fbb0837342a566ff928b211cbb418075a7e744fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Thu, 1 Feb 2024 20:00:45 +
Subject: [PATCH] [clang-tidy] Remove check-specific HeaderFileExtensions and
 ImplementationFileExtensions

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

Fixes #61947
---
 .../DynamicStaticInitializersCheck.cpp| 22 +--
 .../bugprone/DynamicStaticInitializersCheck.h | 10 -
 .../bugprone/SuspiciousIncludeCheck.cpp   | 38 ++
 .../bugprone/SuspiciousIncludeCheck.h | 15 ---
 .../google/GlobalNamesInHeadersCheck.cpp  | 22 +--
 .../google/GlobalNamesInHeadersCheck.h| 10 -
 .../google/UnnamedNamespaceInHeaderCheck.cpp  | 22 +--
 .../google/UnnamedNamespaceInHeaderCheck.h| 10 -
 .../misc/DefinitionsInHeadersCheck.cpp| 39 +++
 .../misc/DefinitionsInHeadersCheck.h  |  9 -
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 17 +---
 .../misc/UseAnonymousNamespaceCheck.cpp   | 22 +--
 .../misc/UseAnonymousNamespaceCheck.h | 10 -
 .../clang-tidy/utils/HeaderGuard.cpp  |  4 --
 .../clang-tidy/utils/HeaderGuard.h| 27 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   | 31 +++
 .../checks/bugprone/suspicious-include.rst| 24 
 .../checks/google/build-namespaces.rst| 15 ---
 .../checks/google/global-names-in-headers.rst | 15 ---
 .../clang-tidy/checks/llvm/header-guard.rst   | 15 ---
 .../checks/misc/definitions-in-headers.rst| 24 
 .../checks/misc/unused-using-decls.rst| 16 +---
 .../checks/misc/use-anonymous-namespace.rst   | 16 +---
 23 files changed, 54 insertions(+), 379 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4a467120181b4..93f35cb2c1a3d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -27,26 +27,8 @@ AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
 
 DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context) {
-  std::optional HeaderFileExtensionsOption =
-  Options.get("HeaderFileExtensions");
-  RawStringHeaderFileExtensions =
-  
HeaderFileExtensionsOption.value_or(utils::defaultHeaderFileExtensions());
-  if (HeaderFileExtensionsOption) {
-if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-HeaderFileExtensions,
-utils::defaultFileExtensionDelimiters())) {
-  this->configurationDiag("Invalid header file extension: '%0'")
-  << RawStringHeaderFileExtensions;
-}
-  } else
-HeaderFileExtensions = Context->getHeaderFileExtensions();
-}
-
-void DynamicStaticInitializersCheck::storeOptions(
-ClangTidyOptions::OptionMap ) {
-  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
-}
+: ClangTidyCheck(Name, Context),
+  HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index d8ac31dc3b850..66ed2828502b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -15,26 +15,16 @@
 namespace clang::tidy::bugprone {
 
 /// Finds dynamically initialized static variables in header files.
-///
-/// The check supports these options:
-///   - `HeaderFileExtensions`: a semicolon-separated list of filename
-/// extensions of header files (The filename extensions should not contain
-/// "." prefix). ";h;hh;hpp;hxx" by default.
-//
-/// For extension-less header files, using an empty string or leaving an
-/// empty string between ";" if there are other filename extensions.
 class DynamicStaticInitializersCheck : public ClangTidyCheck {
 public:
   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions ) const override {
 return LangOpts.CPlusPlus && !LangOpts.ThreadsafeStatics;
   }
-  void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const 

[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-prefer-member-init (PR #80330)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID: 
In-Reply-To:


https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/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

>From e3b3d8b5f8edfd7d8bf759784868431220013a03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 31 Jan 2024 20:25:27 +
Subject: [PATCH 1/2] [clang-tidy] Remove enforcement of rule C.48 from
 cppcoreguidelines-prefer-member-init

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 #62169
---
 .../PreferMemberInitializerCheck.cpp  | 245 ++
 .../PreferMemberInitializerCheck.h|   4 -
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 +
 .../prefer-member-initializer.rst |  54 +---
 ...ize-use-default-member-init-assignment.cpp |  33 ---
 ...izer-modernize-use-default-member-init.cpp |  33 ---
 6 files changed, 100 insertions(+), 277 deletions(-)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index f79a67819bb85..de96c3dc4efef 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -34,27 +34,6 @@ static bool isNoReturnCallStatement(const Stmt *S) {
   return Func->isNoReturn();
 }
 
-static bool isLiteral(const Expr *E) {
-  return isa(E);
-}
-
-static bool isUnaryExprOfLiteral(const Expr *E) {
-  if (const auto *UnOp = dyn_cast(E))
-return isLiteral(UnOp->getSubExpr());
-  return false;
-}
-
-static bool shouldBeDefaultMemberInitializer(const Expr *Value) {
-  if (isLiteral(Value) || isUnaryExprOfLiteral(Value))
-return true;
-
-  if (const auto *DRE = dyn_cast(Value))
-return isa(DRE->getDecl());
-
-  return false;
-}
-
 namespace {
 
 AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
@@ -166,19 +145,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const 
Stmt *S,
 
 PreferMemberInitializerCheck::PreferMemberInitializerCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  IsUseDefaultMemberInitEnabled(
-  Context->isCheckEnabled("modernize-use-default-member-init")),
-  UseAssignment(
-  Options.get("UseAssignment",
-  OptionsView("modernize-use-default-member-init",
-  Context->getOptions().CheckOptions, Context)
-  .get("UseAssignment", false))) {}
-
-void PreferMemberInitializerCheck::storeOptions(
-ClangTidyOptions::OptionMap ) {
-  Options.store(Opts, "UseAssignment", UseAssignment);
-}
+: ClangTidyCheck(Name, Context) {}
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
@@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;
-const bool IsInDefaultMemberInitializer =
-IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-Ctor->isDefaultConstructor() &&
-(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-!Field->hasInClassInitializer() &&
-(!isa(Class->getDeclContext()) ||
- !cast(Class->getDeclContext())->isUnion()) &&
-shouldBeDefaultMemberInitializer(InitValue);
-if (IsInDefaultMemberInitializer) {
-  bool InvalidFix = false;
-  SourceLocation FieldEnd =
-  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
- *Result.SourceManager, getLangOpts());
-  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-  SourceLocation SemiColonEnd;
-  if (auto NextToken = Lexer::findNextToken(
-  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-SemiColonEnd = NextToken->getEndLoc();
-  else
-InvalidFix = true;
-  auto Diag =
-  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
-

[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… (PR #80193)

2024-02-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/80193

>From bfa4ea36a2695ec8d6ea92db588f91d5c818968a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 31 Jan 2024 20:25:27 +
Subject: [PATCH 1/2] [clang-tidy] Remove enforcement of rule C.48 from
 cppcoreguidelines-prefer-member-init

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 #62169
---
 .../PreferMemberInitializerCheck.cpp  | 245 ++
 .../PreferMemberInitializerCheck.h|   4 -
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 +
 .../prefer-member-initializer.rst |  54 +---
 ...ize-use-default-member-init-assignment.cpp |  33 ---
 ...izer-modernize-use-default-member-init.cpp |  33 ---
 6 files changed, 100 insertions(+), 277 deletions(-)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index f79a67819bb85..de96c3dc4efef 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -34,27 +34,6 @@ static bool isNoReturnCallStatement(const Stmt *S) {
   return Func->isNoReturn();
 }
 
-static bool isLiteral(const Expr *E) {
-  return isa(E);
-}
-
-static bool isUnaryExprOfLiteral(const Expr *E) {
-  if (const auto *UnOp = dyn_cast(E))
-return isLiteral(UnOp->getSubExpr());
-  return false;
-}
-
-static bool shouldBeDefaultMemberInitializer(const Expr *Value) {
-  if (isLiteral(Value) || isUnaryExprOfLiteral(Value))
-return true;
-
-  if (const auto *DRE = dyn_cast(Value))
-return isa(DRE->getDecl());
-
-  return false;
-}
-
 namespace {
 
 AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
@@ -166,19 +145,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const 
Stmt *S,
 
 PreferMemberInitializerCheck::PreferMemberInitializerCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  IsUseDefaultMemberInitEnabled(
-  Context->isCheckEnabled("modernize-use-default-member-init")),
-  UseAssignment(
-  Options.get("UseAssignment",
-  OptionsView("modernize-use-default-member-init",
-  Context->getOptions().CheckOptions, Context)
-  .get("UseAssignment", false))) {}
-
-void PreferMemberInitializerCheck::storeOptions(
-ClangTidyOptions::OptionMap ) {
-  Options.store(Opts, "UseAssignment", UseAssignment);
-}
+: ClangTidyCheck(Name, Context) {}
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
@@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;
-const bool IsInDefaultMemberInitializer =
-IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-Ctor->isDefaultConstructor() &&
-(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-!Field->hasInClassInitializer() &&
-(!isa(Class->getDeclContext()) ||
- !cast(Class->getDeclContext())->isUnion()) &&
-shouldBeDefaultMemberInitializer(InitValue);
-if (IsInDefaultMemberInitializer) {
-  bool InvalidFix = false;
-  SourceLocation FieldEnd =
-  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
- *Result.SourceManager, getLangOpts());
-  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-  SourceLocation SemiColonEnd;
-  if (auto NextToken = Lexer::findNextToken(
-  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-SemiColonEnd = NextToken->getEndLoc();
-  else
-InvalidFix = true;
-  auto Diag =
-  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
- " default member initializer")
-  << Field;
-  if (InvalidFix)
-continue;
-  CharSourceRange StmtRange =
-  CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
 
-  SmallString<128> Insertion(
-  {UseAssignment ? " = " : "{",
-   

[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… (PR #80193)

2024-02-01 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks for the review! I agree, check names are not the best. It's a bit of a 
hassle to change them though :/ 

I will fix the comment about the release notes tonight :+1: 

https://github.com/llvm/llvm-project/pull/80193
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… (PR #80193)

2024-01-31 Thread Carlos Galvez via cfe-commits


@@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;
-const bool IsInDefaultMemberInitializer =
-IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-Ctor->isDefaultConstructor() &&
-(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-!Field->hasInClassInitializer() &&
-(!isa(Class->getDeclContext()) ||
- !cast(Class->getDeclContext())->isUnion()) &&
-shouldBeDefaultMemberInitializer(InitValue);
-if (IsInDefaultMemberInitializer) {
-  bool InvalidFix = false;
-  SourceLocation FieldEnd =
-  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
- *Result.SourceManager, getLangOpts());
-  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-  SourceLocation SemiColonEnd;
-  if (auto NextToken = Lexer::findNextToken(
-  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-SemiColonEnd = NextToken->getEndLoc();
-  else
-InvalidFix = true;
-  auto Diag =
-  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
- " default member initializer")
-  << Field;
-  if (InvalidFix)
-continue;
-  CharSourceRange StmtRange =
-  CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
 
-  SmallString<128> Insertion(
-  {UseAssignment ? " = " : "{",
-   Lexer::getSourceText(Result.SourceManager->getExpansionRange(
-InitValue->getSourceRange()),
-*Result.SourceManager, getLangOpts()),
-   UseAssignment ? "" : "}"});
-
-  Diag << FixItHint::CreateInsertion(FieldEnd, Insertion)
-   << FixItHint::CreateRemoval(StmtRange);
-
-} else {

carlosgalvezp wrote:

The diff is very unfortunate, but essentially there's no changes to the code 
inside this "else" block. It's just unindented 2 spaces. The main change is the 
removal of the "if" block.

https://github.com/llvm/llvm-project/pull/80193
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… (PR #80193)

2024-01-31 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/80193

…refer-member-init

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 #62169

>From bfa4ea36a2695ec8d6ea92db588f91d5c818968a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 31 Jan 2024 20:25:27 +
Subject: [PATCH] [clang-tidy] Remove enforcement of rule C.48 from
 cppcoreguidelines-prefer-member-init

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 #62169
---
 .../PreferMemberInitializerCheck.cpp  | 245 ++
 .../PreferMemberInitializerCheck.h|   4 -
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 +
 .../prefer-member-initializer.rst |  54 +---
 ...ize-use-default-member-init-assignment.cpp |  33 ---
 ...izer-modernize-use-default-member-init.cpp |  33 ---
 6 files changed, 100 insertions(+), 277 deletions(-)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index f79a67819bb85..de96c3dc4efef 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -34,27 +34,6 @@ static bool isNoReturnCallStatement(const Stmt *S) {
   return Func->isNoReturn();
 }
 
-static bool isLiteral(const Expr *E) {
-  return isa(E);
-}
-
-static bool isUnaryExprOfLiteral(const Expr *E) {
-  if (const auto *UnOp = dyn_cast(E))
-return isLiteral(UnOp->getSubExpr());
-  return false;
-}
-
-static bool shouldBeDefaultMemberInitializer(const Expr *Value) {
-  if (isLiteral(Value) || isUnaryExprOfLiteral(Value))
-return true;
-
-  if (const auto *DRE = dyn_cast(Value))
-return isa(DRE->getDecl());
-
-  return false;
-}
-
 namespace {
 
 AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
@@ -166,19 +145,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const 
Stmt *S,
 
 PreferMemberInitializerCheck::PreferMemberInitializerCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  IsUseDefaultMemberInitEnabled(
-  Context->isCheckEnabled("modernize-use-default-member-init")),
-  UseAssignment(
-  Options.get("UseAssignment",
-  OptionsView("modernize-use-default-member-init",
-  Context->getOptions().CheckOptions, Context)
-  .get("UseAssignment", false))) {}
-
-void PreferMemberInitializerCheck::storeOptions(
-ClangTidyOptions::OptionMap ) {
-  Options.store(Opts, "UseAssignment", UseAssignment);
-}
+: ClangTidyCheck(Name, Context) {}
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
@@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;
-const bool IsInDefaultMemberInitializer =
-IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
-Ctor->isDefaultConstructor() &&
-(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
-!Field->hasInClassInitializer() &&
-(!isa(Class->getDeclContext()) ||
- !cast(Class->getDeclContext())->isUnion()) &&
-shouldBeDefaultMemberInitializer(InitValue);
-if (IsInDefaultMemberInitializer) {
-  bool InvalidFix = false;
-  SourceLocation FieldEnd =
-  Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
- *Result.SourceManager, getLangOpts());
-  InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
-  SourceLocation SemiColonEnd;
-  if (auto NextToken = Lexer::findNextToken(
-  S->getEndLoc(), *Result.SourceManager, getLangOpts()))
-SemiColonEnd = NextToken->getEndLoc();
-  else
-InvalidFix = true;
-  auto Diag =
-  diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
- " default member initializer")
-  << Field;
-  if 

[clang-tools-extra] [llvm] [clang] [clang-tidy] Remove cert-dcl21-cpp check (PR #80181)

2024-01-31 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp closed 
https://github.com/llvm/llvm-project/pull/80181
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang-tools-extra] [clang-tidy] Remove cert-dcl21-cpp check (PR #80181)

2024-01-31 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

The code formatting job seems to produce incorrect changes.

https://github.com/llvm/llvm-project/pull/80181
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang-tools-extra] [clang-tidy] Remove cert-dcl21-cpp check (PR #80181)

2024-01-31 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/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

>From fdb65ef4805152ad143a120e343d696f8b08d3db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 31 Jan 2024 18:53:00 +
Subject: [PATCH] [clang-tidy] Remove cert-dcl21-cpp check

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
---
 .../clang-tidy/cert/CERTTidyModule.cpp|   3 -
 .../clang-tidy/cert/CMakeLists.txt|   1 -
 .../clang-tidy/cert/PostfixOperatorCheck.cpp  |  80 ---
 .../clang-tidy/cert/PostfixOperatorCheck.h|  34 -
 clang-tools-extra/clangd/TidyFastChecks.inc   |   1 -
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +
 .../docs/clang-tidy/checks/cert/dcl21-cpp.rst |  28 
 .../docs/clang-tidy/checks/list.rst   |   1 -
 .../clang-tidy/checkers/cert/dcl21-cpp.cpp| 134 --
 clang/docs/tools/clang-formatted-files.txt|   2 -
 .../clang-tidy/cert/BUILD.gn  |   1 -
 11 files changed, 3 insertions(+), 285 deletions(-)
 delete mode 100644 clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.cpp
 delete mode 100644 clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.h
 delete mode 100644 clang-tools-extra/docs/clang-tidy/checks/cert/dcl21-cpp.rst
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cert/dcl21-cpp.cpp

diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp 
b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index d334ab8c437d3..b06a903f92b3e 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -33,7 +33,6 @@
 #include "LimitedRandomnessCheck.h"
 #include "MutatingCopyCheck.h"
 #include "NonTrivialTypesLibcMemoryCallsCheck.h"
-#include "PostfixOperatorCheck.h"
 #include "ProperlySeededRandomGeneratorCheck.h"
 #include "SetLongJmpCheck.h"
 #include "StaticObjectExceptionCheck.h"
@@ -239,8 +238,6 @@ class CERTModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "cert-con54-cpp");
 // DCL
-CheckFactories.registerCheck(
-"cert-dcl21-cpp");
 CheckFactories.registerCheck("cert-dcl50-cpp");
 CheckFactories.registerCheck(
 "cert-dcl51-cpp");
diff --git a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
index 889180f62fde9..882735c9d1e0d 100644
--- a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
@@ -12,7 +12,6 @@ add_clang_library(clangTidyCERTModule
   LimitedRandomnessCheck.cpp
   MutatingCopyCheck.cpp
   NonTrivialTypesLibcMemoryCallsCheck.cpp
-  PostfixOperatorCheck.cpp
   ProperlySeededRandomGeneratorCheck.cpp
   SetLongJmpCheck.cpp
   StaticObjectExceptionCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.cpp 
b/clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.cpp
deleted file mode 100644
index 8ff63ade7315d..0
--- a/clang-tools-extra/clang-tidy/cert/PostfixOperatorCheck.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-//===--- PostfixOperatorCheck.cpp - 
clang-tidy-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "PostfixOperatorCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang::tidy::cert {
-
-void PostfixOperatorCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(functionDecl(hasAnyOverloadedOperatorName("++", "--"),
-  unless(isInstantiated()))
- .bind("decl"),
- this);
-}
-
-void PostfixOperatorCheck::check(const MatchFinder::MatchResult ) {
-  const auto *FuncDecl = Result.Nodes.getNodeAs("decl");
-
-  bool HasThis = false;
-  if (const auto *MethodDecl = dyn_cast(FuncDecl))
-HasThis = MethodDecl->isInstance();
-
-  // Check if the operator is a postfix one.
-  if (FuncDecl->getNumParams() != (HasThis ? 1 : 2))
-return;
-
-  SourceRange ReturnRange = FuncDecl->getReturnTypeSourceRange();
-  SourceLocation Location = ReturnRange.getBegin();
-  if (!Location.isValid())
-return;
-
-  QualType ReturnType = FuncDecl->getReturnType();
-
-  // Warn when the operators return a reference.
-  if (const auto *RefType = ReturnType->getAs()) {
-auto Diag = diag(Location, "overloaded %0 returns a reference instead of 

[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks for understanding @11happy ! As you say the learning experience is 
invaluable and will be very useful for the next check. All contributions are 
greatly appreciated :)

I can recommend you look into fairly recent issues - older issues may not have 
been reviewed throughly or simply be forgotten.

https://github.com/llvm/llvm-project/pull/77586
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

2024-01-10 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

I agree with the opinions from Aaron And Piotr above - this check does the 
opposite of readability: it forces people to waste time digging into the 
Standard to find the quote that says the return is not needed. 

Could some argumentation be provided as to why this would be a good check to 
have? What coding guidelines/best practice articles promote this? I cannot 
think of any category where it would fit (besides misc). 

I believe this is a nano-optimization, and premature optimization is the root 
of all evil :) 

https://github.com/llvm/llvm-project/pull/77586
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-30 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Apologies for the late reply, need to fix my mail filter so I don't miss the 
notifications!

IMHO either modernize or readability are suitable categories. Performance can 
vary/be negligible depending on context I suppose?

https://github.com/llvm/llvm-project/pull/72385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-14 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp closed 
https://github.com/llvm/llvm-project/pull/67528
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-14 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From 08b5c95bea5b7bfceeae6dfc4deac764faff87a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/2] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 4 
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1eebf5ea6b3e382..ade3c33b3b9444c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,10 @@ C++ Specific Potentially Breaking Changes
   Clang as a compiler, but it may break assumptions in Clang-based tools
   iterating over the AST.
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on
+  system headers and macros. It will be turned into a hard (non-downgradable)
+  error in the next Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 83d8ad39ee5544ad9bab848901362de0b180b2b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/2] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-13 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

Friendly ping @AaronBallman @shafik 

https://github.com/llvm/llvm-project/pull/67528
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

It seems checks are broken on trunk, I see commits merged with failing 
pre-merge tests. They seem to be unrelated to this patch though.

Is there anything else you'd like fixed before merging? @dwblaikie 
@AaronBallman @shafik 

https://github.com/llvm/llvm-project/pull/67528
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From 7a70366e08f2c2f1181bb74f7716d8b1e3f1b62e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/3] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8f5a67e14c9aba3..6a1afa656a470b4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,6 +71,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 45fe235f06c4c1693e555baab2bedf233bef57e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/3] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp resolved 
https://github.com/llvm/llvm-project/pull/67528
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

I would need some help with the failing pre-merge test, I don't really 
understand why that failure would be related to this patch...

https://github.com/llvm/llvm-project/pull/67528
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/3] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 8dc78e7dda5d1db625eb45a8d32409fe1c91ea87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/3] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 



@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,

carlosgalvezp wrote:

Done. 

https://github.com/llvm/llvm-project/pull/67528
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/2] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 8dc78e7dda5d1db625eb45a8d32409fe1c91ea87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/2] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits


@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,

carlosgalvezp wrote:

Yes, will fix!

https://github.com/llvm/llvm-project/pull/67528
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/67528

…macros

As per review comments on https://reviews.llvm.org/D150226, we should allow for 
one more release before turning this warning into a hard error, by making it 
visible in system headers and macros, so that people are aware of it and can 
work on it.

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-23 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks @shafik , I wasn't aware! I will then close this PR and continue the 
discussion on Phab.

https://github.com/llvm/llvm-project/pull/67170
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-23 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp closed 
https://github.com/llvm/llvm-project/pull/67170
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-22 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Not sure what happens with the failed job in CI, I rebased on latest trunk and 
ran the entire `ninja check-clang` suite and it passed successfully. Do I need 
some special CMake configuration flag to enable the failing test?

About the patch itself - casting outside of range of enum is only UB since 
C++17 - before that it's unspecified. Do we want the error to throw always 
(this patch), or only in C++17 and on?

I started to put up a patch to filter this to only C++17, but then I thought: 
if the compiler is catching something bad, and it can warn about it, why 
shouldn't it?

https://github.com/llvm/llvm-project/pull/67170
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add recursion protection in ExceptionSpecAnalyzer (PR #66810)

2023-09-22 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

To clarify, I'm not concerned about performance, but with code readability and 
maintainability. 

I realize the chain that I wrote above should not lead to recursion due to 
`SkipMethods::Yes` in the relevant call. I'd like to take a closer look at the 
problem, would you be able to share some of the stacktrace that shows how the 
recursion is happening? 

https://github.com/llvm/llvm-project/pull/66810
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-22 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/67170

Casting an int into an enum is undefined behavior if the int is outside of the 
range of the enum. UB is not allowed in constant expressions, therefore the 
compiler must produce a hard error in that case.

However, until now, the compiler produced a warning that could be suppressed. 
It should instead be a hard error, since the program is ill-formed in that 
case, as per the C++ Standard.

This patch turns the warning into an error. Additionally, references to the old 
warning are removed since they are now meaningless.

Fixes #59036

>From b82f22ceee6d344bb3f808079c40193a6e3a12a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Fri, 22 Sep 2023 17:55:49 +
Subject: [PATCH] [clang] Turn -Wenum-constexpr-conversion into a hard error

Casting an int into an enum is undefined behavior if the int is
outside of the range of the enum. UB is not allowed in constant
expressions, therefore the compiler must produce a hard error
in that case.

However, until now, the compiler produced a warning that could be
suppressed. It should instead be a hard error, since the program
is ill-formed in that case, as per the C++ Standard.

This patch turns the warning into an error. Additionally, references
to the old warning are removed since they are now meaningless.

Fixes #59036
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 5 +++--
 clang/lib/AST/ExprConstant.cpp  | 4 ++--
 openmp/cmake/HandleOpenMPOptions.cmake  | 1 -
 openmp/cmake/config-ix.cmake| 1 -
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..1792a2c22261d63 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The downgradable error ``--Wenum-constexpr-conversion`` has been upgraded
+  into a hard error, to comply with the C++ Standard.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..58fbfef18e303ce 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -403,9 +403,10 @@ def warn_integer_constant_overflow : Warning<
 def warn_fixedpoint_constant_overflow : Warning<
   "overflow in expression; result is %0 with type %1">,
   InGroup>;
-def warn_constexpr_unscoped_enum_out_of_range : Warning<
+
+def err_constexpr_unscoped_enum_out_of_range : Error<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fea06b97259fe31..82d659aab28c7d0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13843,13 +13843,13 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
 (Max.slt(Result.getInt().getSExtValue()) ||
  Min.sgt(Result.getInt().getSExtValue(
   Info.Ctx.getDiagnostics().Report(
-  E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range)
+  E->getExprLoc(), diag::err_constexpr_unscoped_enum_out_of_range)
   << llvm::toString(Result.getInt(), 10) << Min.getSExtValue()
   << Max.getSExtValue() << ED;
 else if (!ED->getNumNegativeBits() && ConstexprVar &&
  Max.ult(Result.getInt().getZExtValue()))
   Info.Ctx.getDiagnostics().Report(
-  E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range)
+  E->getExprLoc(), diag::err_constexpr_unscoped_enum_out_of_range)
   << llvm::toString(Result.getInt(), 10) << Min.getZExtValue()
   << Max.getZExtValue() << ED;
   }
diff --git a/openmp/cmake/HandleOpenMPOptions.cmake 
b/openmp/cmake/HandleOpenMPOptions.cmake
index 4d6782a6f0cbe87..81b3d560acf6d8c 100644
--- a/openmp/cmake/HandleOpenMPOptions.cmake
+++ b/openmp/cmake/HandleOpenMPOptions.cmake
@@ -31,7 +31,6 @@ append_if(OPENMP_HAVE_WSIGN_COMPARE_FLAG "-Wsign-compare" 
CMAKE_C_FLAGS CMAKE_CX
 # printed. Therefore, check for whether the compiler supports options in the
 # form -W, and if supported, add the corresponding -Wno- option.
 
-append_if(OPENMP_HAVE_WENUM_CONSTEXPR_CONVERSION_FLAG 

[clang-tools-extra] [clang-tidy] Add recursion protection in ExceptionSpecAnalyzer (PR #66810)

2023-09-21 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Being totally unfamiliar with the code, I have a feeling that we shouldn't be 
fixing in the `analyze` function. `analyze` has 1 single responsibility: wrap 
`analyzeImpl` in order to add cacheability for performance reasons, and it does 
so simply and well, and it does exactly what one would expect - no more no less.

However, the real problem is that `analyzeImpl` ultimately might end up calling 
itself, via `analyzeUnresolvedOrDefaulted -> analyzeRecord -> analyze -> 
analyzeImpl` (IIRC). This is not obvious due to how the code is written, and 
this patch would make it even less obvious IMO. 

In that sense I believe it would make sense to ensure no recursion happens 
somewhere in the chain I described above, not in `analyze`. WDYT?

https://github.com/llvm/llvm-project/pull/66810
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix support for typedefs in readability-identifier-naming (PR #66835)

2023-09-20 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp approved this pull request.

LGTM, thanks for the fix and the great cleanup!

https://github.com/llvm/llvm-project/pull/66835
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix support for typedefs in readability-identifier-naming (PR #66835)

2023-09-20 Thread Carlos Galvez via cfe-commits


@@ -729,3 +729,21 @@ struct forward_declared_as_struct;
 class forward_declared_as_struct {
 };
 
+namespace pr55156 {
+
+typedef enum {
+  VALUE0,
+  VALUE1,
+} ValueType;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for typedef 
'ValueType' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}} value_type_t;
+
+#define STATIC_MACRO static
+STATIC_MACRO void someFunc(ValueType a_v1, const ValueType& a_v2) {}
+// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(value_type_t a_v1, const 
value_type_t& a_v2) {}
+STATIC_MACRO void someFunc(const ValueType** p_a_v1, ValueType (*p_a_v2)()) {}
+// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(const value_type_t** p_a_v1, 
value_type_t (*p_a_v2)()) {}

carlosgalvezp wrote:

Ack!

https://github.com/llvm/llvm-project/pull/66835
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix support for typedefs in readability-identifier-naming (PR #66835)

2023-09-20 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp resolved 
https://github.com/llvm/llvm-project/pull/66835
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix support for typedefs in readability-identifier-naming (PR #66835)

2023-09-20 Thread Carlos Galvez via cfe-commits


@@ -729,3 +729,21 @@ struct forward_declared_as_struct;
 class forward_declared_as_struct {
 };
 
+namespace pr55156 {
+
+typedef enum {
+  VALUE0,
+  VALUE1,
+} ValueType;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for typedef 
'ValueType' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}} value_type_t;
+
+#define STATIC_MACRO static
+STATIC_MACRO void someFunc(ValueType a_v1, const ValueType& a_v2) {}
+// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(value_type_t a_v1, const 
value_type_t& a_v2) {}
+STATIC_MACRO void someFunc(const ValueType** p_a_v1, ValueType (*p_a_v2)()) {}
+// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(const value_type_t** p_a_v1, 
value_type_t (*p_a_v2)()) {}

carlosgalvezp wrote:

Shouldn't we add `CHECK-MESSAGES` here as well?

https://github.com/llvm/llvm-project/pull/66835
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -207,11 +211,13 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
   // allow for T{} to be replaced, even if no CTOR is declared
-  auto HasConstructInitListExpr = has(initListExpr(anyOf(
-  allOf(has(SoughtConstructExpr),
-has(cxxConstructExpr(argumentCountIs(0,
-  has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
-   has(cxxConstructExpr(argumentCountIs(0;
+  auto HasConstructInitListExpr =
+  has(initListExpr(anyOf(initCountIs(0), initCountIs(1)),

carlosgalvezp wrote:

Nit: would it be simpler/more readable with something like `initCountLeq(1)`?

https://github.com/llvm/llvm-project/pull/66169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -207,11 +211,13 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
   // allow for T{} to be replaced, even if no CTOR is declared
-  auto HasConstructInitListExpr = has(initListExpr(anyOf(
-  allOf(has(SoughtConstructExpr),
-has(cxxConstructExpr(argumentCountIs(0,
-  has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
-   has(cxxConstructExpr(argumentCountIs(0;
+  auto HasConstructInitListExpr =
+  has(initListExpr(anyOf(initCountIs(0), initCountIs(1)),

carlosgalvezp wrote:

Would it make sense to briefly document this choice of init list of exactly 0 
or 1 arguments in the line above?

https://github.com/llvm/llvm-project/pull/66169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -1332,6 +1337,17 @@ void testBracedInitTemporaries() {
   v3.push_back(NonTrivialWithCtor{{}});
   v3.push_back({{0}});
   v3.push_back({{}});
+
+  std::vector v4;
+
+  // These should not be noticed or fixed; after the correction, the code won't
+  // compile.
+  v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  v4.push_back(NonTrivialWithIntAndVector{});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{});

carlosgalvezp wrote:

We typically do not use `CHECK-FIXES` to ensure the code has not changed - the 
fact that a warning is not triggered should be enough (see rest of file).

https://github.com/llvm/llvm-project/pull/66169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-17 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp commented:

Should this change be reflected in the Release Notes?

https://github.com/llvm/llvm-project/pull/66504
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] The first PR our of many PRs for the "Initialized Class Members" check. (PR #65189)

2023-09-08 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Thanks for the detailed response @adriannistor !

> will soon become a lot of if-then-else blocks.

In general the decision as to which checks to have should be based on Coding 
Guidelines and user-facing experience - not on implementation complexity. In 
that sense, as a user I would find confusing to have 2 checks that do nearly 
the same.

If I understand the discussion correctly, the intention is to create a check 
that is stricter than the C++ Core Guidelines, is that correct? There is some 
vagueness in the Guidelines as well. Typically we handle this with Options, 
allowing users to enable a more strict or lenient version. Would that be an 
alternative?

Long-term, I believe we should just have 1 single check for "initialize your 
class members". This can be done in different ways, for example expanding the 
C++ Core Guidelines one, or replacing it with this new check (which should have 
relevant configuration options to ensure it behaves according to the spec of 
the Guidelines). I would be fine with temporarily having 2 checks in parallel 
as long as there's a plan for merging them eventually.

> If you would prefer that we write the checker until the end and then 
> upstream, we would be very glad to do that, just let me know!

I think it's great that you are splitting the development into smaller pieces 
so it's easier to do a quality review. Would it however make sense to keep a 
WIP documentation where one can see the approximate roadmap of this check, i.e 
what use cases are implemented and which ones will come? 




https://github.com/llvm/llvm-project/pull/65189
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] The first PR our of many PRs for the "Initialized Class Members" check. (PR #65189)

2023-09-08 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,34 @@
+.. title:: clang-tidy - google-cpp-init-class-members
+
+google-cpp-init-class-members
+=
+
+Checks that class members are initialized in constructors (implicitly or
+explicitly). Reports constructors or classes where class members are not
+initialized. The goal of this check is to eliminate UUM (Use of
+Uninitialized Memory) bugs caused by uninitialized class members.
+
+This check is under active development: the check authors made a few commits
+and are actively working on more commits. Users who want a mature and stable
+check should not use this check yet.
+
+This check is different from ProTypeMemberInitCheck in that this check
+attempts to eliminate UUMs as a bug class, at the expense of false
+positives. The authors of this check will add more documentation about the
+differences with ProTypeMemberInitCheck as the check evolves.
+
+For now, this check reports `X` in the following two patterns:

carlosgalvezp wrote:

It would be good to show what the "fixed" code would look like.

https://github.com/llvm/llvm-project/pull/65189
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] The first PR our of many PRs for the "Initialized Class Members" check. (PR #65189)

2023-09-08 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,34 @@
+.. title:: clang-tidy - google-cpp-init-class-members
+
+google-cpp-init-class-members
+=
+
+Checks that class members are initialized in constructors (implicitly or
+explicitly). Reports constructors or classes where class members are not
+initialized. The goal of this check is to eliminate UUM (Use of
+Uninitialized Memory) bugs caused by uninitialized class members.
+
+This check is under active development: the check authors made a few commits
+and are actively working on more commits. Users who want a mature and stable
+check should not use this check yet.
+
+This check is different from ProTypeMemberInitCheck in that this check

carlosgalvezp wrote:

ProTypeMemberInitCheck is an implementation detail - please refer to the 
user-facing check name (cppcoreguidelines-pro-type-member-init) together with a 
clickable link. Feel free to check out the Release Notes on how we typically 
refer to checks.

https://github.com/llvm/llvm-project/pull/65189
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Adding an initial version of the "Initialized Class Members" checker. (PR #65189)

2023-09-05 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - google-cpp-init-class-members
+
+google-cpp-init-class-members
+=
+
+Checks that class members are initialized in constructors (implicitly or
+explicitly). Reports constructors or classes where class members are not
+initialized. The goal of this checker is to eliminate UUM (Use of
+Uninitialized Memory) bugs caused by uninitialized class members.
+
+This checker is different from ProTypeMemberInitCheck in that this checker
+attempts to eliminate UUMs as a bug class, at the expense of false
+positives.

carlosgalvezp wrote:

It's not entirely clear to me what "UUMs as a bug class" means. Could you 
provide an example where `ProTypeMemberInitCheck` doesn't detect the problem, 
and this check does? Also, why shouldn't that be fixed in 
`ProTypeMemberInitCheck` instead?

https://github.com/llvm/llvm-project/pull/65189
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-04 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp closed 
https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-04 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp resolved 
https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-04 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/7] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/7] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/7] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9d..45039858fffdd3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking 

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/6] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e253802..47de4185667a3e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/6] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3e..a1fab68b0951b9 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/6] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9..45039858fffdd3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking the functions
-as ``= delete``, and 

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= 


carlosgalvezp wrote:

Yes good point, will fix!

https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


carlosgalvezp wrote:

Yep, we could certainly change it to C++11 or later, but I think it's out of 
the scope for this NFC patch. Regarding documentation, I haven't seen that we 
document this detail in other checks, it seems like an implementation detail 
that could cause maintenance effort if documented.

https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 



@@ -3,22 +3,37 @@
 modernize-use-equals-delete
 ===
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
-
-.. code-block:: c++
-
-  struct A {
-  private:
+Identifies unimplemented private special member functions, and recommends using
+``= delete`` for them, as well as relocating them from the ``private`` to the
+``public`` section.
+
+Before the introduction of C++11, the primary method to effectively "erase" a
+particular function involved declaring it as ``private`` without providing a
+definition. This approach would result in either a compiler error (when
+attempting to call a private function) or a linker error (due to an undefined
+reference).
+
+However, subsequent to the advent of C++11, a more conventional approach 
emerged
+for achieving this purpose. It involves flagging functions as ``= delete`` and
+keeping them in the ``public`` section of the class.
+
+To prevent false positives, this check is only active within a translation
+unit where all other member functions have been implemented. The check will
+generate partial fixes by introducing ``= delete``, but the user is responsible
+for manually relocating functions to the ``public`` section.
+
+.. code-block:: c
+
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

carlosgalvezp wrote:

It's already documented on line 42, is there anything else you would like to 
add?

https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/5] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/5] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/5] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9d..45039858fffdd3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking the functions
-as ``= delete``, and keeping them in the 

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/4] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/4] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/4] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9d..45039858fffdd3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking the functions
-as ``= delete``, and keeping them in the ``public`` section.
-
-This 

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/3] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/3] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

>From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:49:49 +
Subject: [PATCH 3/3] Apply suggestions

---
 .../checks/modernize/use-equals-delete.rst| 34 +++
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index a1fab68b0951b9d..45039858fffdd3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,20 +3,26 @@
 modernize-use-equals-delete
 ===
 
-Prior to C++11, the only way to "delete" a given function was to make it
-``private`` and without definition, to generate a compiler error (calling
-private function) or a linker error (undefined reference).
-
-After C++11, the more idiomatic way to achieve this is by marking the functions
-as ``= delete``, and keeping them in the ``public`` section.
-
-This check warns only on 

[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp resolved 
https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH 1/2] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e2538021..47de4185667a3ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

>From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:39:48 +
Subject: [PATCH 2/2] Remove duplication

---
 .../clang-tidy/checks/modernize/use-equals-delete.rst| 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index 47de4185667a3ea..a1fab68b0951b9d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -10,14 +10,11 @@ private function) or a linker error (undefined reference).
 After C++11, the more idiomatic way to achieve this is by marking the functions
 as ``= delete``, and keeping them in the ``public`` section.
 
-This check marks unimplemented private special member functions with ``= 
delete``.
-Additionally, it warns about ``delete``'d functions still kept in the 
``private``
-section, that should be moved to the ``public`` one instead.
-
+This check warns only on unimplemented private **special member functions**.
 To avoid false-positives, this check only applies in a translation unit that 
has
 all other member functions implemented. The check will generate partial fixes
-by adding ``= delete``, but the user must manually move it to the ``public``
-section.
+by adding ``= delete``, but the move the ``public`` section needs to be done
+manually.
 
 .. code-block:: c++
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp edited 
https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/65231:

>From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.

Fixes #65221
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e253802..47de4185667a3e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp review_requested 
https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp review_requested 
https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/65231:

…-delete

So the purpose of the check is more clear. Update examples code to show 
compliant code.

>From 0ffc7aab2f385babd81b57e8116b0433d85cfaf2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sun, 3 Sep 2023 18:24:55 +
Subject: [PATCH] [clang-tidy][NFC][doc] Improve documentation for
 modernize-use-equals-delete

So the purpose of the check is more clear. Update examples code to
show compliant code.
---
 .../checks/modernize/use-equals-delete.rst| 26 ++-
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index c3de904e253802..47de4185667a3e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -3,22 +3,34 @@
 modernize-use-equals-delete
 ===
 
+Prior to C++11, the only way to "delete" a given function was to make it
+``private`` and without definition, to generate a compiler error (calling
+private function) or a linker error (undefined reference).
+
+After C++11, the more idiomatic way to achieve this is by marking the functions
+as ``= delete``, and keeping them in the ``public`` section.
+
 This check marks unimplemented private special member functions with ``= 
delete``.
+Additionally, it warns about ``delete``'d functions still kept in the 
``private``
+section, that should be moved to the ``public`` one instead.
+
 To avoid false-positives, this check only applies in a translation unit that 
has
-all other member functions implemented.
+all other member functions implemented. The check will generate partial fixes
+by adding ``= delete``, but the user must manually move it to the ``public``
+section.
 
 .. code-block:: c++
 
-  struct A {
-  private:
+  // Example: bad
+  class A {
+   private:
 A(const A&);
 A& operator=(const A&);
   };
 
-  // becomes
-
-  struct A {
-  private:
+  // Example: good
+  class A {
+   public:
 A(const A&) = delete;
 A& operator=(const A&) = delete;
   };

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp review_requested 
https://github.com/llvm/llvm-project/pull/65231
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] readability-identifier-naming - fix StructCase and UnionCase in C (PR #65202)

2023-09-03 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/65202
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 2992d08 - [clang-tidy] Do not warn on macros starting with underscore and lowercase letter in bugprone-reserved-identifier

2023-07-30 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-07-30T12:10:48Z
New Revision: 2992d084774f44e7626a7d640fe6c30163db450e

URL: 
https://github.com/llvm/llvm-project/commit/2992d084774f44e7626a7d640fe6c30163db450e
DIFF: 
https://github.com/llvm/llvm-project/commit/2992d084774f44e7626a7d640fe6c30163db450e.diff

LOG: [clang-tidy] Do not warn on macros starting with underscore and lowercase 
letter in bugprone-reserved-identifier

Fixes #64130

Differential Revision: https://reviews.llvm.org/D156608

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
index aaf10f63fb070d..fb04e6e0fa9361 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
@@ -102,13 +102,15 @@ static std::optional 
getUnderscoreCapitalFixup(StringRef Name) {
 }
 
 static bool startsWithUnderscoreInGlobalNamespace(StringRef Name,
-  bool IsInGlobalNamespace) {
-  return IsInGlobalNamespace && Name.size() >= 1 && Name[0] == '_';
+  bool IsInGlobalNamespace,
+  bool IsMacro) {
+  return !IsMacro && IsInGlobalNamespace && Name.size() >= 1 && Name[0] == '_';
 }
 
 static std::optional
-getUnderscoreGlobalNamespaceFixup(StringRef Name, bool IsInGlobalNamespace) {
-  if (startsWithUnderscoreInGlobalNamespace(Name, IsInGlobalNamespace))
+getUnderscoreGlobalNamespaceFixup(StringRef Name, bool IsInGlobalNamespace,
+  bool IsMacro) {
+  if (startsWithUnderscoreInGlobalNamespace(Name, IsInGlobalNamespace, 
IsMacro))
 return std::string(Name.drop_front(1));
   return std::nullopt;
 }
@@ -123,7 +125,7 @@ static std::string getNonReservedFixup(std::string Name) {
 }
 
 static std::optional
-getFailureInfoImpl(StringRef Name, bool IsInGlobalNamespace,
+getFailureInfoImpl(StringRef Name, bool IsInGlobalNamespace, bool IsMacro,
const LangOptions , bool Invert,
ArrayRef AllowedIdentifiers) {
   assert(!Name.empty());
@@ -158,15 +160,16 @@ getFailureInfoImpl(StringRef Name, bool 
IsInGlobalNamespace,
   AppendFailure(DoubleUnderscoreTag, std::move(*Fixup));
 if (auto Fixup = getUnderscoreCapitalFixup(InProgressFixup()))
   AppendFailure(UnderscoreCapitalTag, std::move(*Fixup));
-if (auto Fixup = getUnderscoreGlobalNamespaceFixup(InProgressFixup(),
-   IsInGlobalNamespace))
+if (auto Fixup = getUnderscoreGlobalNamespaceFixup(
+InProgressFixup(), IsInGlobalNamespace, IsMacro))
   AppendFailure(GlobalUnderscoreTag, std::move(*Fixup));
 
 return Info;
   }
   if (!(hasReservedDoubleUnderscore(Name, LangOpts) ||
 startsWithUnderscoreCapital(Name) ||
-startsWithUnderscoreInGlobalNamespace(Name, IsInGlobalNamespace)))
+startsWithUnderscoreInGlobalNamespace(Name, IsInGlobalNamespace,
+  IsMacro)))
 return FailureInfo{NonReservedTag, getNonReservedFixup(std::string(Name))};
   return std::nullopt;
 }
@@ -177,16 +180,17 @@ ReservedIdentifierCheck::getDeclFailureInfo(const 
NamedDecl *Decl,
   assert(Decl && Decl->getIdentifier() && !Decl->getName().empty() &&
  !Decl->isImplicit() &&
  "Decl must be an explicit identifier with a name.");
-  return getFailureInfoImpl(Decl->getName(),
-isa(Decl->getDeclContext()),
-getLangOpts(), Invert, AllowedIdentifiers);
+  return getFailureInfoImpl(
+  Decl->getName(), isa(Decl->getDeclContext()),
+  /*IsMacro = */ false, getLangOpts(), Invert, AllowedIdentifiers);
 }
 
 std::optional
 ReservedIdentifierCheck::getMacroFailureInfo(const Token ,
  const SourceManager &) const {
   return getFailureInfoImpl(MacroNameTok.getIdentifierInfo()->getName(), true,
-getLangOpts(), Invert, AllowedIdentifiers);
+/*IsMacro = */ true, getLangOpts(), Invert,
+AllowedIdentifiers);
 }
 
 RenamerClangTidyCheck::DiagInfo

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a93ff58c60e2c0..000b80aadc0237 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -140,6 +140,10 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Fixed bug in 

[clang-tools-extra] b7c6b39 - [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

2023-07-26 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-07-26T10:26:43Z
New Revision: b7c6b39651b3ffdabf0081c45e0455a04a8be992

URL: 
https://github.com/llvm/llvm-project/commit/b7c6b39651b3ffdabf0081c45e0455a04a8be992
DIFF: 
https://github.com/llvm/llvm-project/commit/b7c6b39651b3ffdabf0081c45e0455a04a8be992.diff

LOG: [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

Since it was deprecated since clang-tidy 16.

Fixes #62020

Differential Revision: https://reviews.llvm.org/D156303

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index bc2ecc6b545536..1efe35a8b8f015 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -157,14 +157,12 @@ static void mapChecks(IO , std::optional 
) {
 
 template <> struct MappingTraits {
   static void mapping(IO , ClangTidyOptions ) {
-bool Ignored = false;
 mapChecks(IO, Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
 IO.mapOptional("ImplementationFileExtensions",
Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
-IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // deprecated
 IO.mapOptional("FormatStyle", Options.FormatStyle);
 IO.mapOptional("User", Options.User);
 IO.mapOptional("CheckOptions", Options.CheckOptions);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 159366222844ec..d22287d4effe49 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,6 +108,9 @@ Improvements to clang-tidy
   functionality using the newly added command line option
   `--enable-module-headers-parsing`.
 
+- Remove configuration option `AnalyzeTemporaryDestructors`, which was 
deprecated since
+  :program:`clang-tidy` 16.
+
 New checks
 ^^
 

diff  --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
index 89d8f4400fca80..af4f66ae3c54f1 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -81,7 +81,6 @@ TEST(ParseConfiguration, ValidConfiguration) {
   "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
   "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
   "HeaderFilterRegex: \".*\"\n"
-  "AnalyzeTemporaryDtors: true\n"
   "User: some.user",
   "Options"));
   EXPECT_TRUE(!!Options);
@@ -115,7 +114,6 @@ TEST(ParseConfiguration, MergeConfigurations) {
   HeaderFileExtensions: ["h","hh"]
   ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
-  AnalyzeTemporaryDtors: true
   User: user1
   ExtraArgs: ['arg1', 'arg2']
   ExtraArgsBefore: ['arg-before1', 'arg-before2']
@@ -130,7 +128,6 @@ TEST(ParseConfiguration, MergeConfigurations) {
   HeaderFileExtensions: ["hpp","hxx"]
   ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
-  AnalyzeTemporaryDtors: false
   User: user2
   ExtraArgs: ['arg3', 'arg4']
   ExtraArgsBefore: ['arg-before3', 'arg-before4']



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] b70e6e9 - [clang-tidy] Warn only for copyable/movable classes in cppcoreguidelines-avoid-const-or-ref-members

2023-07-19 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-07-19T12:05:15Z
New Revision: b70e6e9681925ad06d9899462b9e43250be53f64

URL: 
https://github.com/llvm/llvm-project/commit/b70e6e9681925ad06d9899462b9e43250be53f64
DIFF: 
https://github.com/llvm/llvm-project/commit/b70e6e9681925ad06d9899462b9e43250be53f64.diff

LOG: [clang-tidy] Warn only for copyable/movable classes in 
cppcoreguidelines-avoid-const-or-ref-members

Since that's what the guidelines require.

Fixes #63733

Differential Revision: https://reviews.llvm.org/D155625

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
index b22fa94663d584..6a6e620a4387b0 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
@@ -19,17 +19,86 @@ AST_MATCHER(FieldDecl, isMemberOfLambda) {
   return Node.getParent()->isLambda();
 }
 
+struct MemberFunctionInfo {
+  bool Declared{};
+  bool Deleted{};
+};
+
+struct MemberFunctionPairInfo {
+  MemberFunctionInfo Copy{};
+  MemberFunctionInfo Move{};
+};
+
+MemberFunctionPairInfo getConstructorsInfo(CXXRecordDecl const ) {
+  MemberFunctionPairInfo Constructors{};
+
+  for (CXXConstructorDecl const *Ctor : Node.ctors()) {
+if (Ctor->isCopyConstructor()) {
+  Constructors.Copy.Declared = true;
+  if (Ctor->isDeleted())
+Constructors.Copy.Deleted = true;
+}
+if (Ctor->isMoveConstructor()) {
+  Constructors.Move.Declared = true;
+  if (Ctor->isDeleted())
+Constructors.Move.Deleted = true;
+}
+  }
+
+  return Constructors;
+}
+
+MemberFunctionPairInfo getAssignmentsInfo(CXXRecordDecl const ) {
+  MemberFunctionPairInfo Assignments{};
+
+  for (CXXMethodDecl const *Method : Node.methods()) {
+if (Method->isCopyAssignmentOperator()) {
+  Assignments.Copy.Declared = true;
+  if (Method->isDeleted())
+Assignments.Copy.Deleted = true;
+}
+
+if (Method->isMoveAssignmentOperator()) {
+  Assignments.Move.Declared = true;
+  if (Method->isDeleted())
+Assignments.Move.Deleted = true;
+}
+  }
+
+  return Assignments;
+}
+
+AST_MATCHER(CXXRecordDecl, isCopyableOrMovable) {
+  MemberFunctionPairInfo Constructors = getConstructorsInfo(Node);
+  MemberFunctionPairInfo Assignments = getAssignmentsInfo(Node);
+
+  if (Node.hasSimpleCopyConstructor() ||
+  (Constructors.Copy.Declared && !Constructors.Copy.Deleted))
+return true;
+  if (Node.hasSimpleMoveConstructor() ||
+  (Constructors.Move.Declared && !Constructors.Move.Deleted))
+return true;
+  if (Node.hasSimpleCopyAssignment() ||
+  (Assignments.Copy.Declared && !Assignments.Copy.Deleted))
+return true;
+  if (Node.hasSimpleMoveAssignment() ||
+  (Assignments.Move.Declared && !Assignments.Move.Deleted))
+return true;
+
+  return false;
+}
+
 } // namespace
 
 void AvoidConstOrRefDataMembersCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(fieldDecl(unless(isMemberOfLambda()),
-   hasType(hasCanonicalType(referenceType(
- .bind("ref"),
- this);
-  Finder->addMatcher(fieldDecl(unless(isMemberOfLambda()),
-   hasType(qualType(isConstQualified(
- .bind("const"),
- this);
+  Finder->addMatcher(
+  fieldDecl(
+  unless(isMemberOfLambda()),
+  anyOf(
+  
fieldDecl(hasType(hasCanonicalType(referenceType(.bind("ref"),
+  fieldDecl(hasType(qualType(isConstQualified(.bind("const")),
+  hasDeclContext(cxxRecordDecl(isCopyableOrMovable(,
+  this);
 }
 
 void AvoidConstOrRefDataMembersCheck::check(

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1c542d4c9f2f30..1b8f3bf113c01c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -325,6 +325,11 @@ Changes in existing checks
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
+- Fixed :doc:`cppcoreguidelines-avoid-const-or-ref-data-members
+  ` check
+  to emit warnings only on classes that are copyable/movable, as required by 
the
+  corresponding rule.
+
 - Deprecated C.48 enforcement from 
:doc:`cppcoreguidelines-prefer-member-initializer
   `. Please use
   

[clang-tools-extra] 0d6d8a8 - [clang-tidy] Fix bugprone-assert-side-effect to actually give warnings

2023-05-09 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-05-09T16:45:02Z
New Revision: 0d6d8a853a6ea29b5f461a475a8f8eb7e7ba18e2

URL: 
https://github.com/llvm/llvm-project/commit/0d6d8a853a6ea29b5f461a475a8f8eb7e7ba18e2
DIFF: 
https://github.com/llvm/llvm-project/commit/0d6d8a853a6ea29b5f461a475a8f8eb7e7ba18e2.diff

LOG: [clang-tidy] Fix bugprone-assert-side-effect to actually give warnings

Some time ago a patch was merged to disable all clang-tidy warnings
from system macros. This led to bugprone-assert-side-effect
silently no longer working, since the warnings came from a system
macro. The problem was not detected because the fake assert functions
were implemented in the same file as the test, instead of being a
system include like it's done in the real world.

Move the assert to a proper system header, and fix the code to
warn at the correct location.

This patch is breakdown from https://reviews.llvm.org/D147081
by PiotrZSL.

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

Differential Revision: https://reviews.llvm.org/D150071

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h

Modified: 
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 600a923b211cf..07a987359d4d8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -117,13 +117,13 @@ void AssertSideEffectCheck::check(const 
MatchFinder::MatchResult ) {
   StringRef AssertMacroName;
   while (Loc.isValid() && Loc.isMacroID()) {
 StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
+Loc = SM.getImmediateMacroCallerLoc(Loc);
 
 // Check if this macro is an assert.
 if (llvm::is_contained(AssertMacros, MacroName)) {
   AssertMacroName = MacroName;
   break;
 }
-Loc = SM.getImmediateMacroCallerLoc(Loc);
   }
   if (AssertMacroName.empty())
 return;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
new file mode 100644
index 0..904597ff2184e
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
@@ -0,0 +1,40 @@
+#pragma clang system_header
+
+int abort();
+
+#ifdef NDEBUG
+#define assert(x) 1
+#else
+#define assert(x)  
\
+  if (!(x))
\
+  (void)abort()
+#endif
+
+void print(...);
+#define assert2(e) (__builtin_expect(!(e), 0) ?
\
+   print (#e, __FILE__, __LINE__) : (void)0)
+
+#ifdef NDEBUG
+#define my_assert(x) 1
+#else
+#define my_assert(x)   
\
+  ((void)((x) ? 1 : abort()))
+#endif
+
+#ifdef NDEBUG
+#define not_my_assert(x) 1
+#else
+#define not_my_assert(x)   
\
+  if (!(x))
\
+  (void)abort()
+#endif
+
+#define real_assert(x) ((void)((x) ? 1 : abort()))
+#define wrap1(x) real_assert(x)
+#define wrap2(x) wrap1(x)
+#define convoluted_assert(x) wrap2(x)
+
+#define msvc_assert(expression) (void)(
\
+(!!(expression)) ||
\
+(abort(), 0)   
\
+)

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
index c327007651d4c..ccafeb4b7f3b1 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
@@ -1,47 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t -- 
-config="{CheckOptions: [{key: bugprone-assert-side-effect.CheckFunctionCalls, 
value: true}, {key: bugprone-assert-side-effect.AssertMacros, value: 
'assert,assert2,my_assert,convoluted_assert,msvc_assert'}, {key: 
bugprone-assert-side-effect.IgnoredFunctions, value: 
'MyClass::badButIgnoredFunc'}]}" -- -fexceptions
-
-//===--- assert definition block 
--===//
-int abort() { return 0; }
-
-#ifdef NDEBUG
-#define assert(x) 1
-#else
-#define assert(x)  
\
-  if (!(x))  

[clang-tools-extra] 26f4762 - [clang-tidy] Support SystemHeaders in .clang-tidy

2023-05-07 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-05-07T16:36:30Z
New Revision: 26f476286fbcb5cde51176abb2d3c6c0986bc410

URL: 
https://github.com/llvm/llvm-project/commit/26f476286fbcb5cde51176abb2d3c6c0986bc410
DIFF: 
https://github.com/llvm/llvm-project/commit/26f476286fbcb5cde51176abb2d3c6c0986bc410.diff

LOG: [clang-tidy] Support SystemHeaders in .clang-tidy

A previous patch update the clang-tidy documentation
incorrectly claiming that SystemHeaders can be provided
in the .clang-tidy configuration file.

This patch adds support for it, together with tests.

Differential Revision: https://reviews.llvm.org/D149899

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/system-headers/system_header.h
clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp

Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/index.rst
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index afa88cb4f80d1..bc2ecc6b54553 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -172,6 +172,7 @@ template <> struct MappingTraits {
 IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
 IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
 IO.mapOptional("UseColor", Options.UseColor);
+IO.mapOptional("SystemHeaders", Options.SystemHeaders);
   }
 };
 

diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 2bed6dfda3a0a..74340e1b06cb0 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -134,10 +134,13 @@ option in .clang-tidy file, if any.
  cl::init(""),
  cl::cat(ClangTidyCategory));
 
-static cl::opt
-SystemHeaders("system-headers",
-  desc("Display the errors from system headers."),
-  cl::init(false), cl::cat(ClangTidyCategory));
+static cl::opt SystemHeaders("system-headers", desc(R"(
+Display the errors from system headers.
+This option overrides the 'SystemHeaders' option
+in .clang-tidy file, if any.
+)"),
+   cl::init(false), 
cl::cat(ClangTidyCategory));
+
 static cl::opt LineFilter("line-filter", desc(R"(
 List of files with line ranges to filter the
 warnings. Can be used together with

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b2c36975b80c..f2393a4156548 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -103,6 +103,9 @@ Improvements to clang-tidy
 
 - Fix a potential crash when using the `--dump-config` option.
 
+- Support specifying `SystemHeaders` in the `.clang-tidy` configuration file,
+  with the same functionality as the command-line option `--system-headers`.
+
 New checks
 ^^
 

diff  --git a/clang-tools-extra/docs/clang-tidy/index.rst 
b/clang-tools-extra/docs/clang-tidy/index.rst
index 444d03d6cb08a..41fde5064b8ee 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -211,6 +211,8 @@ An overview of all the command-line options:
  format to stderr. When this option is 
passed,
  these per-TU profiles are instead stored 
as JSON.
 --system-headers   - Display the errors from system headers.
+ This option overrides the 'SystemHeaders' 
option
+ in .clang-tidy file, if any.
 --use-color- Use colors in diagnostics. If not set, 
colors
  will be used if the terminal connected to
  standard output supports colors.

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/system-headers/system_header.h
 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/system-headers/system_header.h
new file mode 100644
index 0..1a3014e83745d
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/system-headers/system_header.h
@@ -0,0 +1 @@
+class Foo { Foo(int); };

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp
new file mode 100644
index 0..9fa990b6aac8c
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp
@@ 

[clang-tools-extra] b507bda - [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

2023-04-17 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-17T06:09:59Z
New Revision: b507bda4552347e00197032526c7ab4a80a853c2

URL: 
https://github.com/llvm/llvm-project/commit/b507bda4552347e00197032526c7ab4a80a853c2
DIFF: 
https://github.com/llvm/llvm-project/commit/b507bda4552347e00197032526c7ab4a80a853c2.diff

LOG: [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

And deprecate identical functionality from
cppcoreguidelines-prefer-member-initializer, which had too many
responsibilities and a tight coupling to the
modernize-use-default-member-init check.

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

Differential Revision: https://reviews.llvm.org/D148460

Added: 

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst

Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index ebffc97127cb6..c0f6a07b57eb5 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/UseDefaultMemberInitCheck.h"
 #include "../modernize/UseOverrideCheck.h"
 #include "../readability/MagicNumbersCheck.h"
 #include "AvoidCapturingLambdaCoroutinesCheck.h"
@@ -110,6 +111,8 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "cppcoreguidelines-special-member-functions");
 CheckFactories.registerCheck("cppcoreguidelines-slicing");
+CheckFactories.registerCheck(
+"cppcoreguidelines-use-default-member-init");
 CheckFactories.registerCheck(
 "cppcoreguidelines-c-copy-assignment-signature");
 CheckFactories.registerCheck(

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 61cd67c1745f9..55c3416235952 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@ New check aliases
   ` to :doc:`bugprone-unsafe-functions
   ` was added.
 
+- New alias :doc:`cppcoreguidelines-use-default-member-init
+  ` to
+  :doc:`modernize-use-default-member-init
+  ` was added.
+
 Changes in existing checks
 ^^
 - Improved :doc:`readability-redundant-string-cstr
@@ -215,6 +220,11 @@ Changes in existing checks
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
+- Deprecated C.48 enforcement from 
:doc:`cppcoreguidelines-prefer-member-initializer
+  `. Please use
+  :doc:`cppcoreguidelines-use-default-member-init
+  ` instead.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   ` check.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
index dea9450b86fd3..803cdbd64edb8 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
@@ -23,6 +23,13 @@ Please note, that this check does not enforce this latter 
rule for
 initializations already implemented as member initializers. For that purpose
 see check `modernize-use-default-member-init 
<../modernize/use-default-member-init.html>`_.
 
+.. note::
+
+  Enforcement of rule C.48 in this check is deprecated, to be removed in
+  :program:`clang-tidy` version 19 (only C.49 will be enforced by this check 
then).
+  Please use `cppcoreguidelines-use-default-member-init 
<../cppcoreguidelines/use-default-member-init.html>`_
+  to enfoce rule C.48.
+
 Example 1
 -
 
@@ -85,6 +92,11 @@ Here ``n`` can be initialized in the constructor 
initialization list, unlike
 
 .. option:: UseAssignment
 
+   Note: this option is deprecated, to be removed in :program:`clang-tidy`
+   version 19. Please use the `UseAssignment` option from
+   `cppcoreguidelines-use-default-member-init 
<../cppcoreguidelines/use-default-member-init.html>`_
+   instead.
+
If this option is set to `true` (by default `UseAssignment` from
`modernize-use-default-member-init
<../modernize/use-default-member-init.html>`_ will be used),

diff  --git 

[clang-tools-extra] 4530c3b - [clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive

2023-04-15 Thread Carlos Galvez via cfe-commits

Author: Nathan James
Date: 2023-04-15T15:07:44Z
New Revision: 4530c3bc4897f6633577de07b61ceb1bf7e79f50

URL: 
https://github.com/llvm/llvm-project/commit/4530c3bc4897f6633577de07b61ceb1bf7e79f50
DIFF: 
https://github.com/llvm/llvm-project/commit/4530c3bc4897f6633577de07b61ceb1bf7e79f50.diff

LOG: [clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive

Fix https://llvm.org/PR49498.
The check notices 2 sides of a conditional operator have types with a different 
constness and so tries to examine the implicit cast.
As one side is infinity, the float narrowing detection sees when its casted to 
a double(which it already was) it thinks the result is out of range.

I've fixed this by just disregarding expressions where the builtin type(without 
quals) match as no conversion would take place.

However this has opened a can of worms. Currenty `float a = 
std::numeric_limits::infinity();` is marked as narrowing.
Whats more suspicious is `double a = std::numeric_limits::infinity();` 
is also marked as narrowing.
It could be argued `double inf -> float inf` is narrowing, but `float inf -> 
double inf` definitely isnt.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D98416

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
index 08157603aab89..f22c9f599a262 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -510,6 +510,8 @@ void NarrowingConversionsCheck::handleBinaryOperator(const 
ASTContext ,
   const BuiltinType *RhsType = getBuiltinType(Rhs);
   if (RhsType == nullptr || LhsType == nullptr)
 return;
+  if (LhsType == RhsType)
+return;
   if (RhsType->getKind() == BuiltinType::Bool && LhsType->isSignedInteger())
 return handleBooleanToSignedIntegral(Context, SourceLoc, Lhs, Rhs);
   if (RhsType->isInteger() && LhsType->getKind() == BuiltinType::Bool)
@@ -549,6 +551,8 @@ void NarrowingConversionsCheck::handleImplicitCast(
   const Expr  = *Cast.getSubExpr();
   if (Lhs.isInstantiationDependent() || Rhs.isInstantiationDependent())
 return;
+  if (getBuiltinType(Lhs) == getBuiltinType(Rhs))
+return;
   if (handleConditionalOperator(Context, Lhs, Rhs))
 return;
   SourceLocation SourceLoc = Lhs.getExprLoc();

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
index 14840df18d038..6cad3204c18e4 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
@@ -54,4 +54,11 @@ void narrow_fp_constants() {
   f = __builtin_nan("0"); // double NaN is not narrowing.
 }
 
+double false_positive_const_qualified_cast(bool t) {
+  double b = 1.0;
+  constexpr double a = __builtin_huge_val();
+  // PR49498 The constness 
diff erence of 'a' and 'b' results in an implicit cast.
+  return t ? b : a;
+}
+
 } // namespace floats



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] d69c362 - [clang-tidy][NFC] Fix format of header file comment in MisleadingCaptureDefaultByValueCheck.h

2023-04-15 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-15T14:49:20Z
New Revision: d69c362dfdc09d9b866cbce007e6342c17af2b2a

URL: 
https://github.com/llvm/llvm-project/commit/d69c362dfdc09d9b866cbce007e6342c17af2b2a
DIFF: 
https://github.com/llvm/llvm-project/commit/d69c362dfdc09d9b866cbce007e6342c17af2b2a.diff

LOG: [clang-tidy][NFC] Fix format of header file comment in 
MisleadingCaptureDefaultByValueCheck.h

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
index 0abf1c9930bea..dcf2ce9afc740 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
@@ -1,5 +1,4 @@
-//===--- MisleadingCaptureDefaultByValueCheck.h - clang-tidy*- C++
-//-*-===//
+//===--- MisleadingCaptureDefaultByValueCheck.h - 
clang-tidy---===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] fa3de2e - [clang-tidy][NFC] Improve doc of cppcoreguidelines-misleading-capture-default-by-value

2023-04-15 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-15T12:07:18Z
New Revision: fa3de2ed2964d18dd0b7457e77416fb4e688c8bd

URL: 
https://github.com/llvm/llvm-project/commit/fa3de2ed2964d18dd0b7457e77416fb4e688c8bd
DIFF: 
https://github.com/llvm/llvm-project/commit/fa3de2ed2964d18dd0b7457e77416fb4e688c8bd.diff

LOG: [clang-tidy][NFC] Improve doc of 
cppcoreguidelines-misleading-capture-default-by-value

Also fix ordering in Release Notes.

Differential Revision: https://reviews.llvm.org/D148424

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
index 06ffa9a1b148..0abf1c9930be 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
@@ -16,11 +16,8 @@ namespace clang::tidy::cppcoreguidelines {
 
 /// Warns when lambda specify a by-value capture default and capture ``this``.
 ///
-/// By-value capture defaults in lambas defined within member functions can be
-/// misleading about whether capturing data member is by value or reference.
-/// For example, [=] will capture local variables by value but member variables
-/// by reference. CppCoreGuideline F.54 suggests to never use by-value capture
-/// default when capturing this.
+/// By-value capture defaults in member functions can be misleading about
+/// whether data members are captured by value or reference.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.html

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fabd7f35a757..55474e1d9bd7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,11 +112,6 @@ New checks
   This check relies heavily on, but is not exclusive to, the functions from
   the *Annex K. "Bounds-checking interfaces"* of C11.
 
-- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
-  ` 
check.
-
-  Warns when lambda specify a by-value capture default and capture ``this``.
-
 - New :doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines
   ` 
check.
 
@@ -124,6 +119,11 @@ New checks
   use-after-free errors and suggests avoiding captures or ensuring the lambda
   closure object has a guaranteed lifetime.
 
+- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
+  ` 
check.
+
+  Warns when lambda specify a by-value capture default and capture ``this``.
+
 - New :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
   ` 
check.
 

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
index 456b20ece0bb..286df16f352c 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
@@ -5,10 +5,14 @@ cppcoreguidelines-misleading-capture-default-by-value
 
 Warns when lambda specify a by-value capture default and capture ``this``.
 
-By-value capture-defaults in member functions can be misleading about
-whether data members are captured by value or reference. For example,
-specifying the capture default ``[=]`` will still capture data members
-by reference.
+By-value capture defaults in member functions can be misleading about whether
+data members are captured by value or reference. This occurs because specifying
+the capture default ``[=]`` actually captures the ``this`` pointer by value,
+not the data members themselves. As a result, data members are still indirectly
+accessed via the captured ``this`` pointer, which essentially means they are
+being accessed by reference. Therefore, even when using ``[=]``, data members
+are effectively captured by reference, which might not align with the user's
+expectations.
 
 Examples:
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] eedbe81 - [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-15T10:10:04Z
New Revision: eedbe81b1c6dfbd85c2a46093e9e862335ad6516

URL: 
https://github.com/llvm/llvm-project/commit/eedbe81b1c6dfbd85c2a46093e9e862335ad6516
DIFF: 
https://github.com/llvm/llvm-project/commit/eedbe81b1c6dfbd85c2a46093e9e862335ad6516.diff

LOG: [clang-tidy] Apply 
cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value 
capture default

Since Cpp Core Guidelines have accepted the change in the rules:
https://github.com/isocpp/CppCoreGuidelines/commit/3c90d590e138c3a1e4eb59234e410e00545326de

Also rename the check accordingly.

Differential Revision: https://reviews.llvm.org/D148340

Added: 

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp



diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
deleted file mode 100644
index 08bd3ebd3c3ec..0
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
+++ /dev/null
@@ -1,44 +0,0 @@
-//===--- AvoidCaptureDefaultWhenCapturingThisCheck.h - clang-tidy*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDCAPTUREDEFAULTWHENCAPTURINGTHISCHECK_H
-#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDCAPTUREDEFAULTWHENCAPTURINGTHISCHECK_H
-
-#include "../ClangTidyCheck.h"
-
-namespace clang::tidy::cppcoreguidelines {
-
-/// Warns when lambda specify a capture default and capture ``this``. The check
-/// also offers fix-its.
-///
-/// Capture defaults in lambas defined within member functions can be
-/// misleading about whether capturing data member is by value or reference.
-/// For example, [=] will capture local variables by value but member variables
-/// by reference. CppCoreGuideline F.54 suggests to always be explicit
-/// and never specify a capture default when also capturing this.
-///
-/// For the user-facing documentation see:
-/// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.html
-class AvoidCaptureDefaultWhenCapturingThisCheck : public ClangTidyCheck {
-public:
-  AvoidCaptureDefaultWhenCapturingThisCheck(StringRef Name,
-ClangTidyContext *Context);
-  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  void check(const ast_matchers::MatchFinder::MatchResult ) override;
-  void storeOptions(ClangTidyOptions::OptionMap ) override;
-  bool isLanguageVersionSupported(const LangOptions ) const override {
-return LangOpts.CPlusPlus11;
-  }
-
-private:
-  bool IgnoreCaptureDefaultByReference;
-};
-
-} // namespace clang::tidy::cppcoreguidelines
-
-#endif // 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDCAPTUREDEFAULTWHENCAPTURINGTHISCHECK_H

diff  --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
index 0804675c63949..700070d6783aa 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
@@ -4,7 +4,6 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_clang_library(clangTidyCppCoreGuidelinesModule
-  AvoidCaptureDefaultWhenCapturingThisCheck.cpp
   AvoidCapturingLambdaCoroutinesCheck.cpp
   AvoidConstOrRefDataMembersCheck.cpp
   AvoidDoWhileCheck.cpp
@@ -15,6 +14,7 @@ add_clang_library(clangTidyCppCoreGuidelinesModule
   InitVariablesCheck.cpp
   InterfacesGlobalInitCheck.cpp

[clang-tools-extra] 132f1d3 - [clang-tidy] Support specifying checks as a list in the config file

2023-04-10 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-10T19:31:33Z
New Revision: 132f1d31fd66c30baf9773bf8f37b36a40fa7039

URL: 
https://github.com/llvm/llvm-project/commit/132f1d31fd66c30baf9773bf8f37b36a40fa7039
DIFF: 
https://github.com/llvm/llvm-project/commit/132f1d31fd66c30baf9773bf8f37b36a40fa7039.diff

LOG: [clang-tidy] Support specifying checks as a list in the config file

Specifying checks as a string is convenient for quickly using
clang-tidy to run a handful of checks. However it is not
suitable for projects that have a long list of enabled or
disabled checks. It is specially troublesome in case one
wants to interleave comments with the checks, to explain
why they are enabled or disabled.

Currently this can be achieved via multiline strings in YAML,
but it's error-prone. For example, comments must end with a
comma for clang-tidy to continue processing the list of globs;
a missing comma will make clang-tidy silently ignore the rest
of the list.

Instead, enable passing a native YAML list to the "Checks"
option in the config file. The implementation is done such
that the old behavior is kept: a user can pass a string
or a list. We can consider deprecating passing the checks
as a string altogether in a future release, to simplify
the internal logic of the YAML parser.

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

Differential Revision: https://reviews.llvm.org/D147876

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file-list-bracket

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file-list-dash

Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/index.rst
clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 84defccde513e..afa88cb4f80d1 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -117,10 +117,48 @@ void yamlize(IO , ClangTidyOptions::OptionMap 
, bool,
   }
 }
 
+struct ChecksVariant {
+  std::optional AsString;
+  std::optional> AsVector;
+};
+
+template <>
+void yamlize(IO , ChecksVariant , bool, EmptyContext ) {
+  if (!IO.outputting()) {
+// Special case for reading from YAML
+// Must support reading from both a string or a list
+Input  = reinterpret_cast(IO);
+if (isa(I.getCurrentNode())) {
+  Checks.AsString = std::string();
+  yamlize(IO, *Checks.AsString, true, Ctx);
+} else if (isa(I.getCurrentNode())) {
+  Checks.AsVector = std::vector();
+  yamlize(IO, *Checks.AsVector, true, Ctx);
+} else {
+  IO.setError("expected string or sequence");
+}
+  }
+}
+
+static void mapChecks(IO , std::optional ) {
+  if (IO.outputting()) {
+// Output always a string
+IO.mapOptional("Checks", Checks);
+  } else {
+// Input as either a string or a list
+ChecksVariant ChecksAsVariant;
+IO.mapOptional("Checks", ChecksAsVariant);
+if (ChecksAsVariant.AsString)
+  Checks = ChecksAsVariant.AsString;
+else if (ChecksAsVariant.AsVector)
+  Checks = llvm::join(*ChecksAsVariant.AsVector, ",");
+  }
+}
+
 template <> struct MappingTraits {
   static void mapping(IO , ClangTidyOptions ) {
 bool Ignored = false;
-IO.mapOptional("Checks", Options.Checks);
+mapChecks(IO, Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
 IO.mapOptional("ImplementationFileExtensions",

diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 09162995a0974..2bed6dfda3a0a 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -52,7 +52,9 @@ Configuration files:
  options. Example:
CheckOptions:
  some-check.SomeOption: 'some value'
-  Checks   - Same as '--checks'.
+  Checks   - Same as '--checks'. Additionally, the list of
+ globs can be specified as a list instead of a
+ string.
   ExtraArgs- Same as '--extra-args'.
   ExtraArgsBefore  - Same as '--extra-args-before'.
   FormatStyle  - Same as '--format-style'.

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index cb10385d8e87f..9c5b86fc8606d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ 

[clang-tools-extra] 712dfec - [clang-tidy] Deprecate cert-dcl21-cpp

2023-04-05 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-05T06:33:40Z
New Revision: 712dfec1781db8aa92782b98cac5517db548b7f9

URL: 
https://github.com/llvm/llvm-project/commit/712dfec1781db8aa92782b98cac5517db548b7f9
DIFF: 
https://github.com/llvm/llvm-project/commit/712dfec1781db8aa92782b98cac5517db548b7f9.diff

LOG: [clang-tidy] Deprecate cert-dcl21-cpp

It is no longer part of the CERT standard. Looking at the
CERT webpage, we can see it has been moved to the Void
section:
https://wiki.sei.cmu.edu/confluence/display/cplusplus/5+The+Void

Differential Revision: https://reviews.llvm.org/D147563

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/cert/dcl21-cpp.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8e57424ae8157..2dfc29e630624 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@ Changes in existing checks
   ` check to also cover constructor
   initializers.
 
+- Deprecated :doc:`cert-dcl21-cpp
+  ` check.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   ` check.

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl21-cpp.rst 
b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl21-cpp.rst
index 2b19172f1736c..9845c2776e11d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl21-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl21-cpp.rst
@@ -3,6 +3,10 @@
 cert-dcl21-cpp
 ==
 
+.. note::
+  This check is deprecated since it's no longer part of the CERT standard.
+  It will be removed in :program:`clang-tidy` version 19.
+
 This check flags postfix ``operator++`` and ``operator--`` declarations
 if the return type is not a const object. This also warns if the return type
 is a reference type.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 2469bd9 - [clang-tidy] Disable misc-definitions-in-headers for declarations in anonymous namespaces

2023-04-01 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-01T19:19:00Z
New Revision: 2469bd98a77242606426f8a5a8a797054c932bf0

URL: 
https://github.com/llvm/llvm-project/commit/2469bd98a77242606426f8a5a8a797054c932bf0
DIFF: 
https://github.com/llvm/llvm-project/commit/2469bd98a77242606426f8a5a8a797054c932bf0.diff

LOG: [clang-tidy] Disable misc-definitions-in-headers for declarations in 
anonymous namespaces

Anonymous namespaces are another way of providing internal linkage,
and the check already ignores other cases of internal linkage in
headers, via "static" or "const".

Anonymous namespaces in headers are definitely a source of pitfalls,
but it's not the responsibility of this check to cover that. Instead,
google-build-namespaces will specifically warn about this issue.

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

Differential Revision: https://reviews.llvm.org/D147379

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 67e1a04a35afe..2c07b30429f96 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -90,13 +90,11 @@ void DefinitionsInHeadersCheck::check(const 
MatchFinder::MatchResult ) {
   // Internal linkage variable definitions are ignored for now:
   //   const int a = 1;
   //   static int b = 1;
+  //   namespace { int c = 1; }
   //
   // Although these might also cause ODR violations, we can be less certain and
   // should try to keep the false-positive rate down.
-  //
-  // FIXME: Should declarations in anonymous namespaces get the same treatment
-  // as static / const declarations?
-  if (!ND->hasExternalFormalLinkage() && !ND->isInAnonymousNamespace())
+  if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
 return;
 
   if (const auto *FD = dyn_cast(ND)) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 156e9d73c7be0..099211e592547 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -199,6 +199,10 @@ Changes in existing checks
   ` check.
   Global options of the same name should be used instead.
 
+- Fixed false positive in :doc:`misc-definitions-in-headers
+  ` to avoid warning on
+  declarations inside anonymous namespaces.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`misc-unused-using-decls
   ` check.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
index dcded6a42a6d9..08aa9d884c239 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
@@ -27,6 +27,7 @@ from multiple translation units.
const int c = 1;
const char* const str2 = "foo";
constexpr int k = 1;
+   namespace { int x = 1; }
 
// Warning: function definition.
int g() {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
index f57cc2c256fef..4cf07077a230a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -108,8 +108,7 @@ int f3() {
 int f5(); // OK: function declaration.
 inline int f6() { return 1; } // OK: inline function definition.
 namespace {
-  int f7() { return 1; }
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f7' defined in a header 
file;
+  int f7() { return 1; }  // OK: each TU defines the function in a unique 
namespace.
 }
 
 int f8() = delete; // OK: the function being marked delete is not callable.
@@ -142,8 +141,7 @@ const char* ca = "foo";
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'ca' defined in a header 
file;
 
 namespace {
-  int e = 2;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'e' defined in a header 
file;
+  int e = 2;  // OK: each TU defines the variable in a unique namespace.
 }
 
 const char* const g = "foo"; // OK: internal linkage variable definition.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 4d4c0f9 - [clang-tidy] Add option to ignore capture default by reference in cppcoreguidelines-avoid-capture-default-when-capturing-this

2023-03-28 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-28T20:36:34Z
New Revision: 4d4c0f9734607bb0423593b060b8fa73c06fe3d3

URL: 
https://github.com/llvm/llvm-project/commit/4d4c0f9734607bb0423593b060b8fa73c06fe3d3
DIFF: 
https://github.com/llvm/llvm-project/commit/4d4c0f9734607bb0423593b060b8fa73c06fe3d3.diff

LOG: [clang-tidy] Add option to ignore capture default by reference in 
cppcoreguidelines-avoid-capture-default-when-capturing-this

The rule exists primarily for when using capture default
by copy "[=]", since member variables will be captured by
reference, which is against developer expectations.

However when the capture default is by reference, then there
is no doubt: everything will be captured by reference. Add
an option to allow just that.

Note: Release Notes do not need update since this check
has been introduced in the current WIP release.

A ticket has been opened at the C++ Core Guidelines repo
to consider updating the rule such that this behavior
is the default one:
https://github.com/isocpp/CppCoreGuidelines/issues/2060

Differential Revision: https://reviews.llvm.org/D147062

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
index 11ef35178765f..1489ca6c442b1 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
@@ -18,6 +18,19 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+AvoidCaptureDefaultWhenCapturingThisCheck::
+AvoidCaptureDefaultWhenCapturingThisCheck(StringRef Name,
+  ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreCaptureDefaultByReference(
+  Options.get("IgnoreCaptureDefaultByReference", false)) {}
+
+void AvoidCaptureDefaultWhenCapturingThisCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IgnoreCaptureDefaultByReference",
+IgnoreCaptureDefaultByReference);
+}
+
 void AvoidCaptureDefaultWhenCapturingThisCheck::registerMatchers(
 MatchFinder *Finder) {
   Finder->addMatcher(lambdaExpr(hasAnyCapture(capturesThis())).bind("lambda"),
@@ -74,24 +87,30 @@ static std::string createReplacementText(const LambdaExpr 
*Lambda) {
 
 void AvoidCaptureDefaultWhenCapturingThisCheck::check(
 const MatchFinder::MatchResult ) {
-  if (const auto *Lambda = Result.Nodes.getNodeAs("lambda")) {
-if (Lambda->getCaptureDefault() != LCD_None) {
-  bool IsThisImplicitlyCaptured = std::any_of(
-  Lambda->implicit_capture_begin(), Lambda->implicit_capture_end(),
-  [](const LambdaCapture ) { return Capture.capturesThis(); });
-  auto Diag = diag(Lambda->getCaptureDefaultLoc(),
-   "lambdas that %select{|implicitly }0capture 'this' "
-   "should not specify a capture default")
-  << IsThisImplicitlyCaptured;
-
-  std::string ReplacementText = createReplacementText(Lambda);
-  SourceLocation DefaultCaptureEnd =
-  findDefaultCaptureEnd(Lambda, *Result.Context);
-  Diag << FixItHint::CreateReplacement(
-  CharSourceRange::getCharRange(Lambda->getCaptureDefaultLoc(),
-DefaultCaptureEnd),
-  ReplacementText);
-}
+  const auto *Lambda = Result.Nodes.getNodeAs("lambda");
+  if (!Lambda)
+return;
+
+  if (IgnoreCaptureDefaultByReference &&
+  Lambda->getCaptureDefault() == LCD_ByRef)
+return;
+
+  if (Lambda->getCaptureDefault() != LCD_None) {
+bool IsThisImplicitlyCaptured = std::any_of(
+Lambda->implicit_capture_begin(), Lambda->implicit_capture_end(),
+[](const LambdaCapture ) { return Capture.capturesThis(); });
+auto Diag = diag(Lambda->getCaptureDefaultLoc(),
+ "lambdas that %select{|implicitly }0capture 'this' "
+ "should not specify a capture default")
+<< IsThisImplicitlyCaptured;
+
+std::string ReplacementText = createReplacementText(Lambda);
+SourceLocation DefaultCaptureEnd =
+findDefaultCaptureEnd(Lambda, *Result.Context);
+Diag << FixItHint::CreateReplacement(
+

[clang-tools-extra] 556600a - [clang-tidy] Add option to ignore user-defined literals in readability-magic-numbers

2023-03-26 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-26T16:41:17Z
New Revision: 556600af6a8a7f241277f7a22c3e3746e7b09123

URL: 
https://github.com/llvm/llvm-project/commit/556600af6a8a7f241277f7a22c3e3746e7b09123
DIFF: 
https://github.com/llvm/llvm-project/commit/556600af6a8a7f241277f7a22c3e3746e7b09123.diff

LOG: [clang-tidy] Add option to ignore user-defined literals in 
readability-magic-numbers

Some user-defined literals operate on implementation-defined types, like
"unsigned long long" and "long double", which are not well supported by
this check. Currently, the check gives warnings when using UDLs, without
giving possiblity to the user to whitelist common UDLs. A good compromise
until a proper fix is found (if any) is to allow the user to disable
warnings on UDLs.

Partially fixes #61656

Differential Revision: https://reviews.llvm.org/D146913

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/readability/magic-numbers.rst

clang-tools-extra/test/clang-tidy/checkers/readability/magic-numbers-userliteral.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index ca81b6e3c6e61..cffe858c39ad1 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
@@ -81,6 +81,8 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, 
ClangTidyContext *Context)
   IgnorePowersOf2IntegerValues(
   Options.get("IgnorePowersOf2IntegerValues", false)),
   IgnoreTypeAliases(Options.get("IgnoreTypeAliases", false)),
+  IgnoreUserDefinedLiterals(
+  Options.get("IgnoreUserDefinedLiterals", false)),
   RawIgnoredIntegerValues(
   Options.get("IgnoredIntegerValues", DefaultIgnoredIntegerValues)),
   RawIgnoredFloatingPointValues(Options.get(
@@ -130,6 +132,7 @@ void 
MagicNumbersCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "IgnorePowersOf2IntegerValues",
 IgnorePowersOf2IntegerValues);
   Options.store(Opts, "IgnoreTypeAliases", IgnoreTypeAliases);
+  Options.store(Opts, "IgnoreUserDefinedLiterals", IgnoreUserDefinedLiterals);
   Options.store(Opts, "IgnoredIntegerValues", RawIgnoredIntegerValues);
   Options.store(Opts, "IgnoredFloatingPointValues",
 RawIgnoredFloatingPointValues);
@@ -243,5 +246,14 @@ bool MagicNumbersCheck::isBitFieldWidth(
   });
 }
 
+bool MagicNumbersCheck::isUserDefinedLiteral(
+const clang::ast_matchers::MatchFinder::MatchResult ,
+const clang::Expr ) const {
+  DynTypedNodeList Parents = Result.Context->getParents(Literal);
+  if (Parents.empty())
+return false;
+  return Parents[0].get() != nullptr;
+}
+
 } // namespace tidy::readability
 } // namespace clang

diff  --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
index 39e9baea3adc8..79787845de619 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
@@ -49,6 +49,10 @@ class MagicNumbersCheck : public ClangTidyCheck {
   bool isBitFieldWidth(const clang::ast_matchers::MatchFinder::MatchResult 
,
const IntegerLiteral ) const;
 
+  bool isUserDefinedLiteral(
+  const clang::ast_matchers::MatchFinder::MatchResult ,
+  const clang::Expr ) const;
+
   template 
   void checkBoundMatch(const ast_matchers::MatchFinder::MatchResult ,
const char *BoundName) {
@@ -72,6 +76,10 @@ class MagicNumbersCheck : public ClangTidyCheck {
 if (isBitFieldWidth(Result, *MatchedLiteral))
   return;
 
+if (IgnoreUserDefinedLiterals &&
+isUserDefinedLiteral(Result, *MatchedLiteral))
+  return;
+
 const StringRef LiteralSourceText = Lexer::getSourceText(
 CharSourceRange::getTokenRange(MatchedLiteral->getSourceRange()),
 *Result.SourceManager, getLangOpts());
@@ -85,6 +93,7 @@ class MagicNumbersCheck : public ClangTidyCheck {
   const bool IgnoreBitFieldsWidths;
   const bool IgnorePowersOf2IntegerValues;
   const bool IgnoreTypeAliases;
+  const bool IgnoreUserDefinedLiterals;
   const StringRef RawIgnoredIntegerValues;
   const StringRef RawIgnoredFloatingPointValues;
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1a53aac8fecf4..03ba9e160b738 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -223,6 +223,9 @@ Changes in existing checks
   behavior of using `i` as the prefix for enum tags, set the 

[clang-tools-extra] f957b8f - [clang-tidy][NFC] Improve naming convention in google-readability-avoid-underscore-in-googletest-name

2023-03-24 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-24T07:22:04Z
New Revision: f957b8fe1efe34ac04d1b2e6381e44edcef056b3

URL: 
https://github.com/llvm/llvm-project/commit/f957b8fe1efe34ac04d1b2e6381e44edcef056b3
DIFF: 
https://github.com/llvm/llvm-project/commit/f957b8fe1efe34ac04d1b2e6381e44edcef056b3.diff

LOG: [clang-tidy][NFC] Improve naming convention in 
google-readability-avoid-underscore-in-googletest-name

According to the Google docs, the convention is
TEST(TestSuiteName, TestName). Apply that convention to the
source code, test and documentation of the check.

Differential Revision: https://reviews.llvm.org/D146713

Added: 


Modified: 
clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp

clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst

clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
index b903f2552b7e..d522d6760af1 100644
--- 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
@@ -47,18 +47,19 @@ class AvoidUnderscoreInGoogletestNameCallback : public 
PPCallbacks {
 if (!isGoogletestTestMacro(MacroName) || !Args ||
 Args->getNumMacroArguments() < 2)
   return;
-const Token *TestCaseNameToken = Args->getUnexpArgument(0);
+const Token *TestSuiteNameToken = Args->getUnexpArgument(0);
 const Token *TestNameToken = Args->getUnexpArgument(1);
-if (!TestCaseNameToken || !TestNameToken)
+if (!TestSuiteNameToken || !TestNameToken)
   return;
-std::string TestCaseNameMaybeDisabled = 
PP->getSpelling(*TestCaseNameToken);
-StringRef TestCaseName = TestCaseNameMaybeDisabled;
-TestCaseName.consume_front(KDisabledTestPrefix);
-if (TestCaseName.contains('_'))
-  Check->diag(TestCaseNameToken->getLocation(),
-  "avoid using \"_\" in test case name \"%0\" according to "
+std::string TestSuiteNameMaybeDisabled =
+PP->getSpelling(*TestSuiteNameToken);
+StringRef TestSuiteName = TestSuiteNameMaybeDisabled;
+TestSuiteName.consume_front(KDisabledTestPrefix);
+if (TestSuiteName.contains('_'))
+  Check->diag(TestSuiteNameToken->getLocation(),
+  "avoid using \"_\" in test suite name \"%0\" according to "
   "Googletest FAQ")
-  << TestCaseName;
+  << TestSuiteName;
 
 std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
 StringRef TestName = TestNameMaybeDisabled;

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
index f2053b4d2fcd..e667fd1b 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
@@ -3,8 +3,8 @@
 google-readability-avoid-underscore-in-googletest-name
 ==
 
-Checks whether there are underscores in googletest test and test case names in
-test macros:
+Checks whether there are underscores in googletest test suite names and test
+names in test macros:
 
 - ``TEST``
 - ``TEST_F``
@@ -18,17 +18,17 @@ For example:
 
 .. code-block:: c++
 
-  TEST(TestCaseName, Illegal_TestName) {}
-  TEST(Illegal_TestCaseName, TestName) {}
+  TEST(TestSuiteName, Illegal_TestName) {}
+  TEST(Illegal_TestSuiteName, TestName) {}
 
-would trigger the check. `Underscores are not allowed`_ in test names nor test
-case names.
+would trigger the check. `Underscores are not allowed`_ in test suite name nor
+test names.
 
-The ``DISABLED_`` prefix, which may be used to `disable individual tests`_, is
-ignored when checking test names, but the rest of the rest of the test name is
-still checked.
+The ``DISABLED_`` prefix, which may be used to
+`disable test suites and individual tests`_, is removed from the test suite 
name
+and test name before checking for underscores.
 
 This check does not propose any fixes.
 
 .. _Underscores are not allowed: 
https://google.github.io/googletest/faq.html#why-should-test-suite-names-and-test-names-not-contain-underscore
-.. _disable individual tests: 
https://google.github.io/googletest/advanced.html#temporarily-disabling-tests
+.. _disable test suites and individual tests: 
https://google.github.io/googletest/advanced.html#temporarily-disabling-tests

diff  --git 

[clang-tools-extra] b767784 - [clang-tidy][NFC] Fix broken link in Release Notes

2023-03-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-23T10:30:15Z
New Revision: b7677846da66fd003a538f87fd8de948cfcc3d6a

URL: 
https://github.com/llvm/llvm-project/commit/b7677846da66fd003a538f87fd8de948cfcc3d6a
DIFF: 
https://github.com/llvm/llvm-project/commit/b7677846da66fd003a538f87fd8de948cfcc3d6a.diff

LOG: [clang-tidy][NFC] Fix broken link in Release Notes

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 89419141cebb..a5f090045615 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -238,8 +238,8 @@ Changes in existing checks
   string for ``Prefix`` or ``Suffix`` options could result in the style not
   being used.
 
-- Fixed an issue in :doc:`google-avoid-underscore-in-googletest-name
-  ` when using
+- Fixed an issue in 
:doc:`google-readability-avoid-underscore-in-googletest-name
+  ` 
when using
   ``DISABLED_`` in the test suite name.
 
 Removed checks



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] b08d35f - [clang-tidy] Ignore DISABLED_ in test suite name in google-avoid-underscore-in-googletest-name

2023-03-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-23T08:31:12Z
New Revision: b08d35f826a6b7696a02f1d811da7a2f951e74a1

URL: 
https://github.com/llvm/llvm-project/commit/b08d35f826a6b7696a02f1d811da7a2f951e74a1
DIFF: 
https://github.com/llvm/llvm-project/commit/b08d35f826a6b7696a02f1d811da7a2f951e74a1.diff

LOG: [clang-tidy] Ignore DISABLED_ in test suite name in 
google-avoid-underscore-in-googletest-name

Test suite name can also be disabled with DISABLED_, not just
the test case name.

Fix also broken link in the test that refers to the explanation
as to why underscores may not be used.

Differential Revision: https://reviews.llvm.org/D146655

Added: 


Modified: 
clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
index c5bd6055072aa..b903f2552b7e6 100644
--- 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
@@ -51,8 +51,10 @@ class AvoidUnderscoreInGoogletestNameCallback : public 
PPCallbacks {
 const Token *TestNameToken = Args->getUnexpArgument(1);
 if (!TestCaseNameToken || !TestNameToken)
   return;
-std::string TestCaseName = PP->getSpelling(*TestCaseNameToken);
-if (TestCaseName.find('_') != std::string::npos)
+std::string TestCaseNameMaybeDisabled = 
PP->getSpelling(*TestCaseNameToken);
+StringRef TestCaseName = TestCaseNameMaybeDisabled;
+TestCaseName.consume_front(KDisabledTestPrefix);
+if (TestCaseName.contains('_'))
   Check->diag(TestCaseNameToken->getLocation(),
   "avoid using \"_\" in test case name \"%0\" according to "
   "Googletest FAQ")

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3f79e8e2a187a..80f5b46681713 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -234,6 +234,10 @@ Changes in existing checks
   string for ``Prefix`` or ``Suffix`` options could result in the style not
   being used.
 
+- Fixed an issue in :doc:`google-avoid-underscore-in-googletest-name
+  ` when using
+  ``DISABLED_`` in the test suite name.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
index 6e8a5c2d50af9..3ab5a6ffe383b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
@@ -87,21 +87,31 @@ TYPED_TEST_P(Illegal_Type_ParameterizedTestCaseName, 
TestName) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: avoid using "_" in test case name 
"Illegal_Type_ParameterizedTestCaseName" according to Googletest FAQ 
[google-readability-avoid-underscore-in-googletest-name]
 
 // Underscores are allowed to disable a test with the DISABLED_ prefix.
-// 
https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-suite-names-and-test-names-not-contain-underscore
+// 
https://google.github.io/googletest/faq.html#why-should-test-suite-names-and-test-names-not-contain-underscore
 TEST(TestCaseName, TestName) {}
 TEST(TestCaseName, DISABLED_TestName) {}
+TEST(DISABLED_TestCaseName, TestName) {}
+TEST(DISABLED_TestCaseName, DISABLED_TestName) {}
 
 TEST_F(TestCaseFixtureName, TestName) {}
 TEST_F(TestCaseFixtureName, DISABLED_TestName) {}
+TEST_F(DISABLED_TestCaseFixtureName, TestName) {}
+TEST_F(DISABLED_TestCaseFixtureName, DISABLED_TestName) {}
 
 TEST_P(ParameterizedTestCaseFixtureName, TestName) {}
 TEST_P(ParameterizedTestCaseFixtureName, DISABLED_TestName) {}
+TEST_P(DISABLED_ParameterizedTestCaseFixtureName, TestName) {}
+TEST_P(DISABLED_ParameterizedTestCaseFixtureName, DISABLED_TestName) {}
 
 TYPED_TEST(TypedTestName, TestName) {}
 TYPED_TEST(TypedTestName, DISABLED_TestName) {}
+TYPED_TEST(DISABLED_TypedTestName, TestName) {}
+TYPED_TEST(DISABLED_TypedTestName, DISABLED_TestName) {}
 
 TYPED_TEST_P(TypeParameterizedTestName, TestName) {}
 TYPED_TEST_P(TypeParameterizedTestName, DISABLED_TestName) {}
+TYPED_TEST_P(DISABLED_TypeParameterizedTestName, TestName) {}
+TYPED_TEST_P(DISABLED_TypeParameterizedTestName, DISABLED_TestName) {}
 
 FRIEND_TEST(FriendTest, Is_NotChecked) {}
 FRIEND_TEST(Friend_Test, IsNotChecked) {}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang-tools-extra] 7e5c48b - [clang-tidy][NFC] Move avoid-underscore-in-googletest-name to google folder

2023-03-22 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-22T18:51:51Z
New Revision: 7e5c48b8bd9ff0ee5de3ba28c833f1225f14e44d

URL: 
https://github.com/llvm/llvm-project/commit/7e5c48b8bd9ff0ee5de3ba28c833f1225f14e44d
DIFF: 
https://github.com/llvm/llvm-project/commit/7e5c48b8bd9ff0ee5de3ba28c833f1225f14e44d.diff

LOG: [clang-tidy][NFC] Move avoid-underscore-in-googletest-name to google folder

Since the check belongs to the google module, it makes sense
that the corresponding test also belongs to the google module.

Differential Revision: https://reviews.llvm.org/D146653

Added: 

clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp

Modified: 


Removed: 

clang-tools-extra/test/clang-tidy/checkers/readability/avoid-underscore-in-googletest-name.cpp



diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-underscore-in-googletest-name.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
similarity index 100%
rename from 
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-underscore-in-googletest-name.cpp
rename to 
clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] efda335 - [clang-tidy] Make readability-container-data-pointer use header

2023-03-11 Thread Carlos Galvez via cfe-commits

Author: Mike Crowe
Date: 2023-03-11T13:59:42Z
New Revision: efda335bf5be11b5ad4f94f3319d859563542553

URL: 
https://github.com/llvm/llvm-project/commit/efda335bf5be11b5ad4f94f3319d859563542553
DIFF: 
https://github.com/llvm/llvm-project/commit/efda335bf5be11b5ad4f94f3319d859563542553.diff

LOG: [clang-tidy] Make readability-container-data-pointer use  header

This requires operator[] to be added to the std::basic_string
implementation.

Depends on D144216

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D145310

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string

clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp

Removed: 




diff  --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
index 614480968f2aa..5cc9cd367e4d9 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -42,6 +42,9 @@ struct basic_string {
   _Type& insert(size_type pos, const C* s);
   _Type& insert(size_type pos, const C* s, size_type n);
 
+  _Type& operator[](size_type);
+  const _Type& operator[](size_type) const;
+
   _Type& operator+=(const _Type& str);
   _Type& operator+=(const C* s);
   _Type& operator=(const _Type& str);

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
index 7f75564ad9dc9..ee2ba6a48752c 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s readability-container-data-pointer %t -- -- 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s readability-container-data-pointer %t -- -- 
-isystem %clang_tidy_headers -fno-delayed-template-parsing
+#include 
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -17,22 +18,6 @@ struct vector {
   const T [](size_type) const;
 };
 
-template 
-struct basic_string {
-  using size_type = size_t;
-
-  basic_string();
-
-  T *data();
-  const T *data() const;
-
-  T [](size_t);
-  const T [](size_type) const;
-};
-
-typedef basic_string string;
-typedef basic_string wstring;
-
 template 
 struct is_integral;
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >