[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
Mon Apr 15 00:08:52 PDT 2024


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

>From 4cb9527430d3c7f9acc518427a29eae0aa7e00d1 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/2] [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 +
 .../bugprone/forwarding-reference-overload.cpp         | 10 ++++++++++
 2 files changed, 11 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/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 5f4f9c937ce9b2da54bbf303ddfa0d18dc92f4dc Mon Sep 17 00:00:00 2001
From: Mike Weller <mweller7 at bloomberg.net>
Date: Mon, 15 Apr 2024 08:07:16 +0100
Subject: [PATCH 2/2] Update release notes

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

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index a7193e90c38da2..1a59449fdf7560 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,7 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Fixed an issue with `bugprone-forwarding-reference-overload` where it would incorrectly flag deleted constructors
 
 New checks
 ^^^^^^^^^^



More information about the cfe-commits mailing list