[PATCH] D146376: Update static_assert message for redundant cases
Krishna Narayanan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 25 05:02:38 PDT 2023
Krishna-13-cyber updated this revision to Diff 508297.
Krishna-13-cyber added a comment.
Updated with the new test cases and implemented the logic suggested for ignoring the BO_LOr operators at the top level. My sincere apologies @tbaeder that I could not place this logic at the first instance.
Thanks!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146376/new/
https://reviews.llvm.org/D146376
Files:
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/static-assert.cpp
Index: clang/test/SemaCXX/static-assert.cpp
===================================================================
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,17 @@
constexpr bool invert(bool b) {
return !b;
}
+
+ /// Bools are printed with disjunction.
+ static_assert(invert(true) || invert(true), ""); // expected-error {{failed}} \
+
+ /// Bools are printed with an expected note.
static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
// expected-note {{evaluates to 'false == true'}}
+ /// Bools are printed with conjunction.
+ static_assert(true && false, ""); // expected-error {{failed}} \
+
/// No notes here since we compare a bool expression with a bool literal.
static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16728,6 +16728,10 @@
if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
return;
+ // Ignore BO_LOr operators at the toplevel.
+ if (Op->getOpcode() == BO_LOr)
+ return;
+
struct {
const clang::Expr *Cond;
Expr::EvalResult Result;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146376.508297.patch
Type: text/x-patch
Size: 1362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230325/8e479a15/attachment.bin>
More information about the cfe-commits
mailing list