[clang-tools-extra] [clang-tidy] Ignore deleted ctor in `bugprone-forwarding-reference-overload` (PR #88138)

Mike Weller via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 17 23:49:28 PDT 2024


https://github.com/MikeWeller updated https://github.com/llvm/llvm-project/pull/88138

>From 483bd05ec3c0575ed6771ef093368d6be19f5d3f Mon Sep 17 00:00:00 2001
From: Mike Weller <mweller7 at bloomberg.net>
Date: Tue, 9 Apr 2024 16:03:31 +0100
Subject: [PATCH 1/5] [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

Fix `bugprone-forwarding-reference-overload` so it doesn't report a constructor that is deleted.
---
 .../bugprone/ForwardingReferenceOverloadCheck.cpp      |  1 +
 clang-tools-extra/docs/ReleaseNotes.rst                |  1 +
 .../bugprone/forwarding-reference-overload.cpp         | 10 ++++++++++
 3 files changed, 12 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index c608fe713f9f5b..e42b40d7b6690e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -73,6 +73,7 @@ void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
   DeclarationMatcher FindOverload =
       cxxConstructorDecl(
           hasParameter(0, ForwardingRefParm),
+          unless(isDeleted()),
           unless(hasAnyParameter(
               // No warning: enable_if as constructor parameter.
               parmVarDecl(hasType(isEnableIf())))),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 1405fb0df1f8dd..4e4dd35242478f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -102,6 +102,7 @@ Improvements to clang-tidy
   similar fashion to what `-header-filter` does for header files.
 - Improved :program:`check_clang_tidy.py` script. Added argument `-export-fixes`
   to aid in clang-tidy and test development.
+- Fixed an issue with `bugprone-forwarding-reference-overload` where it would incorrectly flag deleted constructors
 
 New checks
 ^^^^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
index 38b0691bc9f1ec..92dfb718bb51b7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
@@ -251,3 +251,13 @@ class Test10 {
   Test10(T &&Item, E e)
       : e(e){}
 };
+
+// A deleted ctor cannot hide anything
+class Test11 {
+public:
+  template <typename T>
+  Test11(T&&) = delete;
+
+  Test11(const Test11 &) = default;
+  Test11(Test11 &&) = default;
+};

>From 49eccb42605236abb56cef2950a6d1a4273b45cb Mon Sep 17 00:00:00 2001
From: Mike Weller <mweller7 at bloomberg.net>
Date: Mon, 15 Apr 2024 13:55:54 +0100
Subject: [PATCH 2/5] fixup! [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

---
 clang-tools-extra/docs/ReleaseNotes.rst | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 4e4dd35242478f..b3d710535f625a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -102,7 +102,6 @@ Improvements to clang-tidy
   similar fashion to what `-header-filter` does for header files.
 - Improved :program:`check_clang_tidy.py` script. Added argument `-export-fixes`
   to aid in clang-tidy and test development.
-- Fixed an issue with `bugprone-forwarding-reference-overload` where it would incorrectly flag deleted constructors
 
 New checks
 ^^^^^^^^^^
@@ -287,6 +286,10 @@ Changes in existing checks
   check by resolving fix-it overlaps in template code by disregarding implicit
   instances.
 
+- Improved :doc:`bugprone-forwarding-reference-overload
+  <clang-tidy/checks/bugprone/forwarding-reference-overload>`
+  check to not flag deleted constructors which are unable to hide anything.
+
 Removed checks
 ^^^^^^^^^^^^^^
 

>From fd545ed87cab79e33dbc7de42a1d136114615fe4 Mon Sep 17 00:00:00 2001
From: Mike Weller <mweller7 at bloomberg.net>
Date: Mon, 15 Apr 2024 15:13:18 +0100
Subject: [PATCH 3/5] fixup! [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

---
 clang-tools-extra/docs/ReleaseNotes.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index b3d710535f625a..c504335676ac46 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -147,6 +147,10 @@ Changes in existing checks
   <clang-tidy/checks/bugprone/assert-side-effect>` check by detecting side
   effect from calling a method with non-const reference parameters.
 
+- Improved :doc:`bugprone-forwarding-reference-overload
+  <clang-tidy/checks/bugprone/forwarding-reference-overload>`
+  check to not flag deleted constructors which are unable to hide anything.
+
 - Improved :doc:`bugprone-inc-dec-in-conditions
   <clang-tidy/checks/bugprone/inc-dec-in-conditions>` check to ignore code
   within unevaluated contexts, such as ``decltype``.
@@ -286,10 +290,6 @@ Changes in existing checks
   check by resolving fix-it overlaps in template code by disregarding implicit
   instances.
 
-- Improved :doc:`bugprone-forwarding-reference-overload
-  <clang-tidy/checks/bugprone/forwarding-reference-overload>`
-  check to not flag deleted constructors which are unable to hide anything.
-
 Removed checks
 ^^^^^^^^^^^^^^
 

>From bab66e16f29367fa44002d9d31c328607c734354 Mon Sep 17 00:00:00 2001
From: Mike Weller <mweller7 at bloomberg.net>
Date: Mon, 15 Apr 2024 15:27:15 +0100
Subject: [PATCH 4/5] fixup! [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

---
 clang-tools-extra/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index c504335676ac46..f2fc699df76f6a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -149,7 +149,7 @@ Changes in existing checks
 
 - Improved :doc:`bugprone-forwarding-reference-overload
   <clang-tidy/checks/bugprone/forwarding-reference-overload>`
-  check to not flag deleted constructors which are unable to hide anything.
+  check to ignore deleted constructors which won't hide other overloads.
 
 - Improved :doc:`bugprone-inc-dec-in-conditions
   <clang-tidy/checks/bugprone/inc-dec-in-conditions>` check to ignore code

>From 6d54fa7db7297a965353790d9db261678273f460 Mon Sep 17 00:00:00 2001
From: Mike Weller <mweller7 at bloomberg.net>
Date: Thu, 18 Apr 2024 07:48:54 +0100
Subject: [PATCH 5/5] fixup! [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

formatting
---
 .../clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp   | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index e42b40d7b6690e..e7be8134781e48 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -72,8 +72,7 @@ void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
 
   DeclarationMatcher FindOverload =
       cxxConstructorDecl(
-          hasParameter(0, ForwardingRefParm),
-          unless(isDeleted()),
+          hasParameter(0, ForwardingRefParm), unless(isDeleted()),
           unless(hasAnyParameter(
               // No warning: enable_if as constructor parameter.
               parmVarDecl(hasType(isEnableIf())))),



More information about the cfe-commits mailing list