[clang] [Clang] Treat default template argument as constant expressions (PR #107073)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 05:06:31 PDT 2024


================
@@ -960,6 +960,8 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
       EnterExpressionEvaluationContext ConstantEvaluated(
           Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
       DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseInitializer());
+      if (DefaultArg.isUsable())
+        DefaultArg = Actions.ActOnConstantExpression(DefaultArg);
----------------
zyn0217 wrote:

OK, I'm sold. (The *intervening scope* concept is still a bit harder for me to understand at the moment, so I'll probably look into it at some point.)

Feel free to merge this after one nit, which makes it a bit simpler

```cpp
DefaultArg = Actions.ActOnConstantExpression(ParseInitializer());
```

It would also be great if you could add the record-type case to the test. :)

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


More information about the cfe-commits mailing list