<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2635</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="2635"></A><H4>2635.
  
Constrained structured bindings
</H4>
<B>Section: </B>9.1&#160; [<A href="https://wg21.link/dcl.pre">dcl.pre</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++23
 &#160;&#160;&#160;

 <B>Submitter: </B>Corentin Jabot
 &#160;&#160;&#160;

 <B>Date: </B>2022-10-20<BR>


<P>[Accepted as a DR at the November, 2022 meeting.]</P>



<P>Consider:</P>

<PRE>
template&lt;class T&gt; concept C = true;
C auto [x, y] = std::pair{1, 2}; //<SPAN CLASS="cmnt"> ok?</SPAN>
</PRE>

<P>Subclause 9.1 [<A href="https://wg21.link/dcl.pre#6">dcl.pre</A>] paragraph 6 specifies:</P>

<BLOCKQUOTE>

A <I>simple-declaration</I> with an <I>identifier-list</I> is called a
<I>structured binding declaration</I> (9.7 [<A href="https://wg21.link/dcl.struct.bind">dcl.struct.bind</A>]). If
the <I>decl-specifier-seq</I> contains any <I>decl-specifier</I> other
than static, thread_local, auto (9.2.9.7 [<A href="https://wg21.link/dcl.spec.auto">dcl.spec.auto</A>]),
or <I>cv-qualifier</I> s, the program is ill-formed.

</BLOCKQUOTE>

<P>Use of the word "contains" leads to an interpretation that
any <I>placeholder-type-specifier</I>
(9.2.9.7.1 [<A href="https://wg21.link/dcl.spec.auto.general">dcl.spec.auto.general</A>]), possibly including
a <I>type-constraint</I>, is valid here, since
a <I>placeholder-type-specifier</I> is a <I>decl-specifier</I> and
"contains" <TT>auto</TT>.</P>

<P>However, paper P1141R2 (Yet another approach for constrained
declarations), applied in November 2018, expressly excludes structured
bindings from constrained <TT>auto</TT>:</P>

<BLOCKQUOTE>

Structured bindings do deduce auto in some cases; however, the auto is
deduced from the whole (and not from the individual components). It is
somewhat doubtful that applying the constraint to the whole, as
opposed to (for example) applying separately to each component, is the
correct semantic. Therefore, we propose to defer enabling the
application of constraints to structured bindings to separate papers.

</BLOCKQUOTE>

<P>Notwithstanding, clang, gcc, and MSVC accept the example.</P>

<P><B>Proposed resolution (approved by CWG 2022-10-21):</B></P>

<P>Change in 9.1 [<A href="https://wg21.link/dcl.pre#6">dcl.pre</A>] paragraph 6 specifies:</P>

<BLOCKQUOTE>

A <I>simple-declaration</I> with an <I>identifier-list</I> is called a
<I>structured binding declaration</I> (9.7 [<A href="https://wg21.link/dcl.struct.bind">dcl.struct.bind</A>]).
<DEL>If the <I>decl-specifier-seq</I> contains
any <I>decl-specifier</I> other than static, thread_local, auto
(9.2.9.7 [<A href="https://wg21.link/dcl.spec.auto">dcl.spec.auto</A>]), or <I>cv-qualifier</I>s, the program
is ill-formed.</DEL>
<INS>Each <I>decl-specifier</I> in the <I>decl-specifier-seq</I> shall
be <TT>static</TT>, <TT>thread_local</TT>, <TT>auto</TT>
(9.2.9.7 [<A href="https://wg21.link/dcl.spec.auto">dcl.spec.auto</A>]), or a <I>cv-qualifier</I>.</INS>

<INS>[ Example:</INS>

<PRE class="ins">
template&lt;class T&gt; concept C = true;
C auto [x, y] = std::pair{1, 2}; //<SPAN CLASS="cmnt"> error: constrained placeholder-type-specifier not permitted for structured bindings</SPAN>
</PRE>

<INS> -- end example ]</INS>

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
