================
@@ -2371,6 +2371,20 @@ StmtResult Parser::ParseForStatement(SourceLocation 
*TrailingElseLoc,
 
   MisleadingIndentationChecker MIChecker(*this, MSK_for, ForLoc);
 
+  // If this is an expansion statement with a known expansion size of 0, parse
+  // the body as a discarded statement.
+  bool ShouldEnterDiscardedContext = false;
+  if (ESD && ForRangeStmt.isUsable()) {
+    auto *Pattern = ForRangeStmt.getAs<CXXExpansionStmtPattern>();
+    ShouldEnterDiscardedContext = Pattern->getExpansionSize() == 0u;
----------------
Sirraide wrote:

`if constexpr` behaves the same way:

```c++
bool ShouldEnter = ConstexprCondition && !*ConstexprCondition;
Sema::ExpressionEvaluationContext Context =
    Sema::ExpressionEvaluationContext::DiscardedStatement;
if (NotLocation.isInvalid() && IsConsteval) {
  Context = Sema::ExpressionEvaluationContext::ImmediateFunctionContext;
  ShouldEnter = true;
}

EnterExpressionEvaluationContext PotentiallyDiscarded(
    Actions, Context, nullptr,
    Sema::ExpressionEvaluationContextRecord::EK_Other, ShouldEnter);
```
i.e. `ShouldEnter` is `false` if `ConstexprCondition` is `std::nullopt`.

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

Reply via email to