[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 04:03:15 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:

How about
```cpp
DefaultArg = Actions.ActOnConstantExpression(ParseInitializer())
```

Besides, I still don't understand why we shouldn't accept such code, according to the approach taken here
```cpp
struct S {};

void foo()
{
    constexpr S x{};
    auto a = []<auto = x>{};
}
```

but rather accept only non-record-type cases
```cpp
void foo()
{
    constexpr int x{};
    auto a = []<auto = x>{};
}
```

Can you add some standard quotes here?

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


More information about the cfe-commits mailing list