[clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (#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 #108846
This commit is contained in:
parent
30bb186389
commit
dc2963c8d7
@ -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())),
|
||||
|
@ -360,6 +360,11 @@ Changes in existing checks
|
||||
case of the literal suffix in fixes and fixing false positive for implicit
|
||||
conversion of comparison result in C23.
|
||||
|
||||
- Improved :doc:`readability-redundant-casting
|
||||
<clang-tidy/checks/readability/redundant-casting>` check
|
||||
by addressing a false positive in aggregate initialization through
|
||||
parenthesized list.
|
||||
|
||||
- Improved :doc:`readability-redundant-smartptr-get
|
||||
<clang-tidy/checks/readability/redundant-smartptr-get>` check to
|
||||
remove `->`, when redundant `get()` is removed.
|
||||
|
@ -1,10 +1,18 @@
|
||||
// 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++11,c++14,c++17 %s readability-redundant-casting %t -- -- -fno-delayed-template-parsing
|
||||
// RUN: %check_clang_tidy -std=c++11,c++14,c++17 -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++11,c++14,c++17 -check-suffix=,ALIASES %s readability-redundant-casting %t -- \
|
||||
// RUN: -config='{CheckOptions: { readability-redundant-casting.IgnoreTypeAliases: true }}' \
|
||||
// RUN: -- -fno-delayed-template-parsing
|
||||
// RUN: %check_clang_tidy -std=c++20 %s readability-redundant-casting %t -- \
|
||||
// RUN: -- -fno-delayed-template-parsing -D CXX_20=1
|
||||
// RUN: %check_clang_tidy -std=c++20 -check-suffix=,MACROS %s readability-redundant-casting %t -- \
|
||||
// RUN: -config='{CheckOptions: { readability-redundant-casting.IgnoreMacros: false }}' \
|
||||
// RUN: -- -fno-delayed-template-parsing -D CXX_20=1
|
||||
// RUN: %check_clang_tidy -std=c++20 -check-suffix=,ALIASES %s readability-redundant-casting %t -- \
|
||||
// RUN: -config='{CheckOptions: { readability-redundant-casting.IgnoreTypeAliases: true }}' \
|
||||
// RUN: -- -fno-delayed-template-parsing -D CXX_20=1
|
||||
|
||||
struct A {};
|
||||
struct B : A {};
|
||||
@ -57,6 +65,12 @@ void testDiffrentTypesCast(B& value) {
|
||||
A& a7 = static_cast<A&>(value);
|
||||
}
|
||||
|
||||
#ifdef CXX_20
|
||||
void testParenListInitExpr(A value) {
|
||||
B b = static_cast<B>(value);
|
||||
}
|
||||
#endif
|
||||
|
||||
void testCastingWithAuto() {
|
||||
auto a = getA();
|
||||
A& a8 = static_cast<A&>(a);
|
||||
|
Loading…
x
Reference in New Issue
Block a user