[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
Tue Apr 9 08:45:26 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] [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;
+};



More information about the cfe-commits mailing list