Skip to content

[clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck #109741

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

Merged
merged 6 commits into from
Jan 11, 2025

Conversation

dl8sd11
Copy link
Contributor

@dl8sd11 dl8sd11 commented Sep 24, 2024

Exclude CXXParenListInitExpr from RedundantCastingCheck because there are false positive cases. Currently, we can't think of positive cases for CXXParenListInitExpr. This can be improved by following the initListExpr method if we can come up with some positive cases.

Fixes #108846

Exclude CXXParenListInitExpr from RedundantCastingCheck because
there are false positive cases. Currently, we can't think of
positive cases for CXXParenListInitExpr. This can be improve
by following the initListExpr method if we can come up with
some positive cases.
Copy link

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.

@llvmbot
Copy link
Member

llvmbot commented Sep 24, 2024

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

@llvm/pr-subscribers-clang-tidy

Author: Tommy Chen (dl8sd11)

Changes

Exclude CXXParenListInitExpr from RedundantCastingCheck because there are false positive cases. Currently, we can't think of positive cases for CXXParenListInitExpr. This can be improved by following the initListExpr method if we can come up with some positive cases.

#108846


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

2 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp (+5)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp (+7-3)
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
index b9ff0e81cbc522..fb85eb1628afbd 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
@@ -108,6 +108,10 @@ void RedundantCastingCheck::registerMatchers(MatchFinder *Finder) {
 
   auto BitfieldMemberExpr = memberExpr(member(fieldDecl(isBitField())));
 
+  const ast_matchers::internal::VariadicDynCastAllOfMatcher<
+      Stmt, CXXParenListInitExpr>
+      cxxParenListInitExpr; // NOLINT(readability-identifier-naming)
+
   Finder->addMatcher(
       explicitCastExpr(
           unless(hasCastKind(CK_ConstructorConversion)),
@@ -117,6 +121,7 @@ void RedundantCastingCheck::registerMatchers(MatchFinder *Finder) {
           hasDestinationType(qualType().bind("dstType")),
           hasSourceExpression(anyOf(
               expr(unless(initListExpr()), unless(BitfieldMemberExpr),
+                   unless(cxxParenListInitExpr()),
                    hasType(qualType().bind("srcType")))
                   .bind("source"),
               initListExpr(unless(hasInit(1, expr())),
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
index 30cac6bd5cca06..d94452d84a5841 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
@@ -1,8 +1,8 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s readability-redundant-casting %t -- -- -fno-delayed-template-parsing
-// RUN: %check_clang_tidy -std=c++11-or-later -check-suffix=,MACROS %s readability-redundant-casting %t -- \
+// RUN: %check_clang_tidy -std=c++20-or-later %s readability-redundant-casting %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++20-or-later -check-suffix=,MACROS %s readability-redundant-casting %t -- \
 // RUN:   -config='{CheckOptions: { readability-redundant-casting.IgnoreMacros: false }}' \
 // RUN:   -- -fno-delayed-template-parsing
-// RUN: %check_clang_tidy -std=c++11-or-later -check-suffix=,ALIASES %s readability-redundant-casting %t -- \
+// RUN: %check_clang_tidy -std=c++20-or-later -check-suffix=,ALIASES %s readability-redundant-casting %t -- \
 // RUN:   -config='{CheckOptions: { readability-redundant-casting.IgnoreTypeAliases: true }}' \
 // RUN:   -- -fno-delayed-template-parsing
 
@@ -57,6 +57,10 @@ void testDiffrentTypesCast(B& value) {
   A& a7 = static_cast<A&>(value);
 }
 
+void testParenListInitExpr(A value) {
+  B b = static_cast<B>(value);
+}
+
 void testCastingWithAuto() {
   auto a = getA();
   A& a8 = static_cast<A&>(a);

@EugeneZelenko
Copy link
Contributor

Please mention changes in Release Notes.

@dl8sd11 dl8sd11 changed the title [clang-tidy] eclude CXXParenListInitExpr from RedundantCastingCheck [clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck Sep 24, 2024
[clang-tidy] exclude CXXParenListInitExpr

Exclude CXXParenListInitExpr from RedundantCastingCheck because
there are false positive cases. Currently, we can't think of
positive cases for CXXParenListInitExpr. This can be improve
by following the initListExpr method if we can come up with
some positive cases.
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.

Except single comment, looks fine.

@dl8sd11 dl8sd11 requested a review from PiotrZSL September 25, 2024 14:54
Copy link
Contributor

@felix642 felix642 left a comment

Choose a reason for hiding this comment

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

LGTM.

@5chmidti
Copy link
Contributor

5chmidti commented Oct 3, 2024

Actually, shouldn't this check instead change an explicit cast for a CXXParenListExpr from static_cast<C>(42) to C(42)? Doing this would be fairly simple and there should not be any case that wouldn't support it FWICT.

@PiotrZSL
Copy link
Member

Actually, shouldn't this check instead change an explicit cast for a CXXParenListExpr from static_cast<C>(42) to C(42)

Yes, but that's secondary. As in such case this could be seen as an FunctionalCast.

@PiotrZSL PiotrZSL merged commit dc2963c into llvm:main Jan 11, 2025
9 checks passed
Copy link

@dl8sd11 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!

BaiXilin pushed a commit to BaiXilin/llvm-fix-vnni-instr-types that referenced this pull request Jan 12, 2025
…lvm#109741)

Exclude CXXParenListInitExpr from RedundantCastingCheck because there
are false positive cases. Currently, we can't think of positive cases
for CXXParenListInitExpr. This can be improved by following the
initListExpr method if we can come up with some positive cases.

Fixes llvm#108846
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] readability-redundant-casting false positive on inheritance
6 participants