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

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 04:53:43 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);
----------------
cor3ntin wrote:

I believe it is, yes (I agree it is deeply weird)

Per https://eel.is/c++draft/basic#def.odr-10, if x is odr-used, the program is ill-formed 
(x is a local variable, there is an intervening lambda scope and x is not captured)

So x can't be odr used. And per https://eel.is/c++draft/basic#def.odr-5 - it would be

I agree that this is weird. It might be worth asking CWG
However, i think the change is correct _regardless_ of further bugs with captures.

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


More information about the cfe-commits mailing list