[PATCH] D146376: Update static_assert message for redundant cases
Krishna Narayanan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 30 05:52:58 PDT 2023
Krishna-13-cyber updated this revision to Diff 509632.
Krishna-13-cyber added a comment.
Herald added subscribers: llvm-commits, kadircet, arphaman.
Herald added a project: LLVM.
- Updated patch
- Added testcases for chained operators
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
llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===================================================================
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -23,6 +23,7 @@
"//clang/lib/Lex",
"//clang/lib/Sema",
"//clang/lib/Serialization",
+ "//clang/lib/Testing",
"//clang/lib/Tooling",
"//clang/lib/Tooling/Core",
"//clang/lib/Tooling/Inclusions",
Index: clang/test/SemaCXX/static-assert.cpp
===================================================================
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
constexpr bool invert(bool b) {
return !b;
}
+
+ static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
// expected-note {{evaluates to 'false == true'}}
+ static_assert(true && false, ""); // expected-error {{failed}}
+ static_assert(invert(true) || invert(true) || false, ""); // expected-error {{failed}}
+ static_assert((true && invert(true)) || false, ""); // expected-error {{failed}}
+ static_assert(true && invert(false) && invert(true), ""); // 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
@@ -16715,7 +16715,7 @@
/// Try to print more useful information about a failed static_assert
/// with expression \E
void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
- if (const auto *Op = dyn_cast<BinaryOperator>(E)) {
+ if (const auto *Op = dyn_cast<BinaryOperator>(E);Op && Op->getOpcode() != BO_LOr) {
const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146376.509632.patch
Type: text/x-patch
Size: 2155 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230330/7e4dae90/attachment.bin>
More information about the llvm-commits
mailing list