Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] Ignore deleted ctor in bugprone-forwarding-reference-overload #88138

Merged

Conversation

MikeWeller
Copy link
Contributor

Fix bugprone-forwarding-reference-overload so it doesn't report a constructor that is deleted.

@MikeWeller
Copy link
Contributor Author

MikeWeller commented Apr 9, 2024

Fixes #88128

Copy link

github-actions bot commented Apr 9, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@MikeWeller MikeWeller changed the title [clang-tidy] Ignore delete ctor in bugprone-forwarding-reference-overload [clang-tidy] Ignore deleted ctor in bugprone-forwarding-reference-overload Apr 9, 2024
@EugeneZelenko
Copy link
Contributor

Please mention changes in Release Notes.

@MikeWeller MikeWeller force-pushed the fix-deleted-forwarding-reference-overload branch from 6c188e7 to 4cb9527 Compare April 9, 2024 15:45
@MikeWeller MikeWeller marked this pull request as ready for review April 9, 2024 15:50
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 9, 2024

@llvm/pr-subscribers-clang-tidy

Author: Mike Weller (MikeWeller)

Changes

Fix bugprone-forwarding-reference-overload so it doesn't report a constructor that is deleted.


Full diff: https://github.com/llvm/llvm-project/pull/88138.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp (+1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp (+10)
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;
+};

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 9, 2024

@llvm/pr-subscribers-clang-tools-extra

Author: Mike Weller (MikeWeller)

Changes

Fix bugprone-forwarding-reference-overload so it doesn't report a constructor that is deleted.


Full diff: https://github.com/llvm/llvm-project/pull/88138.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp (+1)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp (+10)
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;
+};

Copy link
Member

@PiotrZSL PiotrZSL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing release notes entry, except that looks fine.

@MikeWeller
Copy link
Contributor Author

Sorry, didn't realize there are release notes I can updated in the change itself. Will do this Monday.

…rload`

Fix `bugprone-forwarding-reference-overload` so it doesn't report a constructor that is deleted.
@MikeWeller MikeWeller force-pushed the fix-deleted-forwarding-reference-overload branch from 5f4f9c9 to 483bd05 Compare April 15, 2024 07:15
@MikeWeller
Copy link
Contributor Author

Given the small size of the change I just did a rebase and force push to resolve conflicts with the release notes.

@MikeWeller
Copy link
Contributor Author

@PiotrZSL apologies, have put it in the correct location. Is there a way to preview/check the :doc: thing? I assume there is some kind of preprocessor/tool step for this? I copied what the rest are doing and put the appropriate section of the https://clang.llvm.org/extra/clang-tidy/checks/bugprone/forwarding-reference-overload.html URL.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move it to line 149, to keep checks in alphabetical order.

Copy link
Contributor

@HerrCai0907 HerrCai0907 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in source code part.

@@ -286,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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use more clear description in release note.
e.g. by ignoring deleted ctor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in bab66e1, let me know if you have a better suggestion

@MikeWeller
Copy link
Contributor Author

FYI I don't have merge privs, not sure if I need to ping anybody. Then again I still see "This workflow requires approval from a maintainer", possibly because this is my first contribution?

@HerrCai0907
Copy link
Contributor

I can help you to merge it. 😄

Copy link

github-actions bot commented Apr 17, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@HerrCai0907
Copy link
Contributor

please fix format issue.git-clang-format is helpful.

@HerrCai0907 HerrCai0907 merged commit 9760b6b into llvm:main Apr 18, 2024
4 of 5 checks passed
Copy link

@MikeWeller Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@MikeWeller MikeWeller deleted the fix-deleted-forwarding-reference-overload branch April 18, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang-tidy bugprone-forwarding-reference-overload false positive on = delete; constructor
5 participants