[PATCH] D147551: [clang-tidy] Fix init-list handling in readability-implicit-bool-conversion
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 5 03:42:21 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdfa8f5b13e58: [clang-tidy] Fix init-list handling in readability-implicit-bool-conversion (authored by PiotrZSL).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147551/new/
https://reviews.llvm.org/D147551
Files:
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
@@ -471,3 +471,10 @@
}
} // namespace ignore_1bit_bitfields
+
+namespace PR47000 {
+ int to_int(bool x) { return int{x}; }
+
+ using IntType = int;
+ int to_int2(bool x) { return IntType{x}; }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,10 @@
behavior of using `i` as the prefix for enum tags, set the `EnumConstantPrefix`
option to `i` instead of using `EnumConstantHungarianPrefix`.
+- Fixed a false positive in :doc:`readability-implicit-bool-conversion
+ <clang-tidy/checks/readability/implicit-bool-conversion>` check warning would
+ be unnecessarily emitted for explicit cast using direct list initialization.
+
- Added support to optionally ignore user-defined literals in
:doc:`readability-magic-numbers<clang-tidy/checks/readability/magic-numbers>`.
Index: clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -262,7 +262,10 @@
expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
has(ignoringImplicit(
memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)))))),
- hasParent(explicitCastExpr())));
+ hasParent(explicitCastExpr()),
+ expr(hasType(qualType().bind("type")),
+ hasParent(initListExpr(hasParent(explicitCastExpr(
+ hasType(qualType(equalsBoundNode("type"))))))))));
auto ImplicitCastFromBool = implicitCastExpr(
anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating),
// Prior to C++11 cast from bool literal to pointer was allowed.
@@ -290,7 +293,7 @@
unless(ExceptionCases), unless(has(BoolXor)),
// Retrieve also parent statement, to check if we need
// additional parens in replacement.
- anyOf(hasParent(stmt().bind("parentStmt")), anything()),
+ optionally(hasParent(stmt().bind("parentStmt"))),
unless(isInTemplateInstantiation()),
unless(hasAncestor(functionTemplateDecl())))
.bind("implicitCastToBool")),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147551.511037.patch
Type: text/x-patch
Size: 2865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230405/4c155654/attachment.bin>
More information about the cfe-commits
mailing list