[clang] [Clang] [C++26] Implement P1306R5 Expansion Statements (PR #165195)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 3 05:31:50 PST 2025


================
@@ -376,6 +376,7 @@ LANGOPT(ConstexprCallDepth, 32, 512, Benign,
         "maximum constexpr call depth")
 LANGOPT(ConstexprStepLimit, 32, 1048576, Benign,
         "maximum constexpr evaluation steps")
+LANGOPT(MaxTemplateForExpansions, 32, 256, Benign, "maximum template for expansions")
 LANGOPT(EnableNewConstInterp, 1, 0, Benign,
----------------
Sirraide wrote:

The main reason I introduced a limit is because if someone does this
```c++
void f() {
    int x[10000000];
    template for (auto y : x) {}
}
```
we basically just hang ‘for ever’ (I haven’t actually timed it, but it’s definitely longer than a miniute; I didn’t wait for it to terminate on its own). As I understand it, the purpose of similar limits (e.g. for constant evaluation steps) is to prevent us from just hanging if a user ends up writing code like this, and I believe this is a similar situation. I can definitely see this happening accidentally with destructuring and iterating expansion statements.

https://github.com/llvm/llvm-project/pull/165195


More information about the cfe-commits mailing list