Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CWG3140 Allowing expansion over non-constant std::array
  • Loading branch information
burblebee authored and tkoeppe committed Apr 12, 2026
commit 0d2ab00dfd2b13d7461f01e695b7c1f20021478e
2 changes: 1 addition & 1 deletion source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4977,7 +4977,7 @@
\pnum
The sixth context is when a temporary object is created
in the \grammarterm{expansion-initializer}
of a destructuring expansion statement.
of an iterating or destructuring expansion statement.
If such a temporary object would otherwise be destroyed
at the end of that \grammarterm{expansion-initializer},
the object persists for the lifetime of the reference
Expand Down
26 changes: 14 additions & 12 deletions source/statements.tex
Original file line number Diff line number Diff line change
Expand Up @@ -874,41 +874,43 @@
\begin{codeblock}
{
@\grammarterm{init-statement}@
constexpr decltype(auto) @\exposidnc{range}@ = (@\grammarterm{expansion-initializer}@);
constexpr auto @\exposidnc{begin}@ = @\exposidnc{begin-expr}@; // see \ref{stmt.ranged}
constexpr auto @\exposidnc{end}@ = @\exposidnc{end-expr}@; // see \ref{stmt.ranged}

@\opt{constexpr}@ decltype(auto) @\exposidnc{range}@ = (@\grammarterm{expansion-initializer}@);
@\opt{constexpr}@ auto @\exposidnc{begin}@ = @\exposidnc{begin-expr}@; // see \ref{stmt.ranged}
@$S_{0}$@
@\vdots@
@$S_{N-1}$@
}
\end{codeblock}
where $N$ is the result of evaluating the expression
\begin{codeblock}
[] consteval {
[&] consteval {
std::ptrdiff_t result = 0;
for (auto i = @\exposid{begin}@; i != @\exposid{end}@; ++i) ++result;
auto b = @\exposid{begin-expr}@;
auto e = @\exposid{end-expr}@;
for (; b != e; ++b) ++result;
return result; // distance from \exposid{begin} to \exposid{end}
}()
\end{codeblock}
and $S_{i}$ is
\begin{codeblock}
{
constexpr auto @\exposid{iter}@ = @\exposid{begin}@ + decltype(begin - begin){@\placeholder{i}@};
@\opt{constexpr}@ auto @\exposid{iter}@ = @\exposid{begin}@ + decltype(begin - begin){@\placeholder{i}@};
@\grammarterm{for-range-declaration}@ = *@\exposid{iter}@;
@\grammarterm{compound-statement}@
}
\end{codeblock}
The variables \exposid{range}, \exposid{begin}, \exposid{end}, and \exposid{iter}
The variables \exposid{range}, \exposid{begin}, and \exposid{iter}
are defined for exposition only.
The keyword \keyword{constexpr} is present in the declarations
of \exposid{range}, \exposid{begin}, and \exposid{iter}
if and only if
\keyword{constexpr} is one of the \grammarterm{decl-specifier}{s} of
the \grammarterm{decl-specifier-seq} of
the \grammarterm{for-range-declaration}.
The identifier \tcode{\placeholder{i}} is considered to be
a prvalue of type \tcode{std::ptrdiff_t};
the program is ill-formed if
\tcode{\placeholder{i}} is not representable as such a value.
\begin{note}
The instantiation is ill-formed if \exposid{range}
is not a constant expression\iref{expr.const.const}.
\end{note}

\item
Otherwise, $S$ is a destructuring expansion statement and,
Expand Down