On 11/18/25 2:36 AM, Jakub Jelinek wrote:
On Mon, Nov 17, 2025 at 01:26:28PM -0500, Marek Polacek wrote:
For the https://gcc.gnu.org/pipermail/gcc/2025-November/246977.html
issues I've filed https://github.com/cplusplus/CWG/issues/805
and got there some responses.  One possibility is to change
the iterating expansion statement http://eel.is/c++draft/stmt.expand#5.2
line from
constexpr auto&& range = expansion-initializer;
to
constexpr decltype(auto) range = (expansion-initializer);
(for our partly pre-CWG3044 implementation with static before it).

The following patch on top of the 2 earlier expansion-stmt patches
attempts to implement it, though not sure if it should be committed
until at least a CWG is filed for it with some proposed resolution.

FWIW, I think we should wait a little.

Sure, I just wanted to post it publicly, so that others can check it out.

This sounds like CWG 2126 which we partially implement (PR101588):

"a temporary object of non-volatile const-qualified literal type whose
lifetime is extended to that of a variable that is usable in constant
expressions" is usable in a constant expression
std::span<const int> is a literal type so it should work?

std::span<const int> doesn't have const-qualified type though, only
the reference type that will refer to it has const std::span<const int>&
type.
The CWG2126 example uses const-qualified type:
typedef const int CI[3];
constexpr CI &ci = CI{11, 22, 33};
static_assert(ci[1] == 22, "");

+             location_t range_loc = cp_expr_loc_or_loc (range_expr, loc);
+             range_expr
+               = finish_parenthesized_expr (cp_expr (range_expr, range_loc));
+             tree auto_node = make_decltype_auto ();
+             tree range_type
+               = cp_build_qualified_type (auto_node, TYPE_QUAL_CONST);
+             range_type = do_auto_deduction (range_type, range_expr,
+                                             auto_node);
+
+             /* Create the __range variable.  */
+             range_temp = build_decl (input_location, VAR_DECL,
+                                      for_range__identifier, range_type);
+             TREE_USED (range_temp) = 1;
+             DECL_ARTIFICIAL (range_temp) = 1;

This is so close to build_range_temp that I think it should get
a "bool expansion_stmt_p" parm so that we can reuse the do_auto_deduction
and further code.

Perhaps, it looked small enough for me, just 4 function calls and two flag
setting stmts, the rest is different.  But can change sure, or part of
build_range_temp could be outlined to finish_range_temp that this could use.

I think I agree with Marek's suggestion.  OK with that change.

Jason

Reply via email to