================
@@ -2462,6 +2467,37 @@ StmtResult Parser::ParseBreakStatement() {
   return ParseBreakOrContinueStatement(/*IsContinue=*/false);
 }
 
+StmtResult Parser::ParseContractAssertStatement() {
+  assert(Tok.is(tok::kw_contract_assert) && "expected contract_assert");
+  if (!getLangOpts().CPlusPlus26)
+    Diag(Tok, diag::err_contracts_require_cxx26);
+  else if (!getLangOpts().Contracts)
+    Diag(Tok, diag::err_contracts_disabled);
+  SourceLocation ContractAssertLoc = ConsumeToken();
+
+  ParsedAttributes Attrs(AttrFactory);
+  MaybeParseCXX11Attributes(Attrs);
+
+  BalancedDelimiterTracker T(*this, tok::l_paren);
+  if (T.expectAndConsume(diag::err_expected_lparen_after, "contract_assert")) {
+    SkipUntil(tok::semi, StopBeforeMatch);
+    return Actions.ActOnNullStmt(ContractAssertLoc,
+                                 /*HasLeadingEmptyMacro=*/false);
+  }
+
+  EnterExpressionEvaluationContext Evaluated(
+      Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
+  ExprResult Predicate = ParseConditionalExpression();
----------------
yronglin wrote:

Hmm, IIUC, we should clear the full-expr cleanup state when discard the 
predicate expr, the following code would tigger clang crash:

```cpp
struct A {
  ~A();
  bool ok() const;
};

void f() {
  contract_assert(A{}.ok()); // Don't crash.
}
```


https://github.com/llvm/llvm-project/pull/221139
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to