]> granicus.if.org Git - clang/commitdiff
[Sema]improve static_assert(!expr)
authorClement Courbet <courbet@google.com>
Tue, 11 Dec 2018 07:04:49 +0000 (07:04 +0000)
committerClement Courbet <courbet@google.com>
Tue, 11 Dec 2018 07:04:49 +0000 (07:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348830 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
test/SemaCXX/static-assert.cpp

index 56302d624844c811679e900def113fd8db17312f..cb6e32fc5e581f7152c8b7a474961eef7280ffd1 100644 (file)
@@ -3071,6 +3071,20 @@ static void prettyPrintFailedBooleanCondition(llvm::raw_string_ostream &OS,
     }
     return;
   }
+  if (const auto *Paren = dyn_cast<ParenExpr>(FailedCond)) {
+    OS << "(";
+    prettyPrintFailedBooleanCondition(OS, Paren->getSubExpr(), Policy);
+    OS << ")";
+    return;
+  }
+  // If this is !(BooleanExpression), try pretty-printing the inner expression.
+  const auto *UnaryOp = dyn_cast<UnaryOperator>(FailedCond);
+  if (UnaryOp && UnaryOp->getOpcode() == UO_LNot) {
+    OS << "!";
+    prettyPrintFailedBooleanCondition(OS, UnaryOp->getSubExpr(), Policy);
+    return;
+  }
+
   FailedCond->printPretty(OS, nullptr, Policy);
 }
 
index 38f82091ae7839f13bfb7e0d7519aa70bb012763..8c666b0dd9063f4cfe602cb16ec1d2c13b0d58ba 100644 (file)
@@ -111,6 +111,10 @@ static_assert(std::is_same<ExampleTypes::T, ExampleTypes::U>::value, "message");
 // expected-error@-1{{static_assert failed due to requirement 'std::is_same<int, float>::value' "message"}}
 static_assert(std::is_const<ExampleTypes::T>::value, "message");
 // expected-error@-1{{static_assert failed due to requirement 'std::is_const<int>::value' "message"}}
+static_assert(!std::is_const<const ExampleTypes::T>::value, "message");
+// expected-error@-1{{static_assert failed due to requirement '!std::is_const<int>::value' "message"}}
+static_assert(!(std::is_const<const ExampleTypes::T>::value), "message");
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const<int>::value)' "message"}}
 
 struct BI_tag {};
 struct RAI_tag : BI_tag {};