TEMPLATE_FOR_EXPR (r) = expansion_init;
TEMPLATE_FOR_BODY (r) = do_pushlevel (sk_block);
+ /* We don't know yet if range_decl will be initialized by constant
+ expression or not. */
+ if (VAR_P (range_decl))
+ {
+ DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (range_decl) = 1;
+ if (decl_maybe_constant_var_p (range_decl)
+ /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
+ && !TYPE_REF_P (TREE_TYPE (range_decl)))
+ TREE_CONSTANT (range_decl) = true;
+ /* Make it value dependent. */
+ retrofit_lang_decl (range_decl);
+ SET_DECL_DEPENDENT_INIT_P (range_decl, 1);
+ }
+
/* Parse the body of the expansion-statement. */
parser->in_statement = IN_EXPANSION_STMT;
bool prev = note_iteration_stmt_body_start ();
orig_decl = TREE_VEC_ELT (orig_decl, 0);
tree decl = tsubst (orig_decl, args, complain, in_decl);
maybe_push_decl (decl);
+ if (VAR_P (decl))
+ {
+ retrofit_lang_decl (decl);
+ SET_DECL_DEPENDENT_INIT_P (decl, 1);
+ }
cp_decomp decomp_d, *decomp = NULL;
if (DECL_DECOMPOSITION_P (decl))
--- /dev/null
+// PR c++/124488
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+void
+foo ()
+{
+ template for (constexpr int a : { 42 }) // { dg-warning "'template for' only available with" "" { target c++23_down } }
+ auto b = [] () { return a; };
+}
+
+void
+bar (int x)
+{
+ template for (const int a : { 42, ++x, 5 }) // { dg-warning "'template for' only available with" "" { target c++23_down } }
+ const int b = a;
+}