[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)
llvm-svn: 348830

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

index 56302d6..cb6e32f 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 38f8209..8c666b0 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 {};