From: Clement Courbet Date: Tue, 11 Dec 2018 07:04:49 +0000 (+0000) Subject: [Sema]improve static_assert(!expr) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62efde54b2386a4c051f7cb5d5c8d288815524cb;p=clang [Sema]improve static_assert(!expr) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348830 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 56302d6248..cb6e32fc5e 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -3071,6 +3071,20 @@ static void prettyPrintFailedBooleanCondition(llvm::raw_string_ostream &OS, } return; } + if (const auto *Paren = dyn_cast(FailedCond)) { + OS << "("; + prettyPrintFailedBooleanCondition(OS, Paren->getSubExpr(), Policy); + OS << ")"; + return; + } + // If this is !(BooleanExpression), try pretty-printing the inner expression. + const auto *UnaryOp = dyn_cast(FailedCond); + if (UnaryOp && UnaryOp->getOpcode() == UO_LNot) { + OS << "!"; + prettyPrintFailedBooleanCondition(OS, UnaryOp->getSubExpr(), Policy); + return; + } + FailedCond->printPretty(OS, nullptr, Policy); } diff --git a/test/SemaCXX/static-assert.cpp b/test/SemaCXX/static-assert.cpp index 38f82091ae..8c666b0dd9 100644 --- a/test/SemaCXX/static-assert.cpp +++ b/test/SemaCXX/static-assert.cpp @@ -111,6 +111,10 @@ static_assert(std::is_same::value, "message"); // expected-error@-1{{static_assert failed due to requirement 'std::is_same::value' "message"}} static_assert(std::is_const::value, "message"); // expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}} +static_assert(!std::is_const::value, "message"); +// expected-error@-1{{static_assert failed due to requirement '!std::is_const::value' "message"}} +static_assert(!(std::is_const::value), "message"); +// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value)' "message"}} struct BI_tag {}; struct RAI_tag : BI_tag {};