<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 3013</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="3013"></A><H4>3013.
  
Disallowing macros for <TT>#embed</TT> parameters
</H4>
<B>Section: </B>15.4.1&#160; [<A href="https://wg21.link/cpp.embed.gen">cpp.embed.gen</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD7
 &#160;&#160;&#160;

 <B>Submitter: </B>Hubert Tong
 &#160;&#160;&#160;

 <B>Date: </B>2025-02-15<BR>


<P>[Accepted at the June, 2025 meeting.]</P>



<P>Subclause 16.4.5.3.3 [<A href="https://wg21.link/macro.names#2">macro.names</A>] paragraph 2 specifies a
prohibition against keywords, alternative tokens, and attributes being
used as macro names.  There is no such protection for parameter names
of <TT>#embed</TT>, but the use of <I>embed-parameter</I>s should be
protected there and in the <TT>__has_embed</TT> argument.</P>

<P>Arguably, 16.4.5.3.3 [<A href="https://wg21.link/macro.names">macro.names</A>] constrains only programs
that use the standard library, because header files of the standard
library must be able to rely on a sane environment; see also
16.4.5.3.1 [<A href="https://wg21.link/reserved.names.general">reserved.names.general</A>]:</P>

<BLOCKQUOTE>

The C++ standard library reserves the following kinds of names: ...

</BLOCKQUOTE>

<P>Arguably, standard library headers can be crafted or auto-generated
such that they do not make use of <TT>#embed</TT>, or at least not
use <TT>#embed</TT> with parameters.  In any case, this would be a
concern of the standard library, not of the core language.</P>

<P><B>Proposed resolution (approved by CWG 2025-06-20):</B></P>

<OL>
<LI>
<P>Change in 15.1 [<A href="https://wg21.link/cpp.pre#3">cpp.pre</A>] paragraph 3 as follows:</P>

<BLOCKQUOTE>

<INS>If one of the <I>pp-tokens</I> of a <TT>#embed</TT> directive
(before macro replacement) is the <I>identifier</I>
<TT>limit</TT>, <TT>prefix</TT>, <TT>suffix</TT>, or
<TT>if_empty</TT> and that <I>identifier</I> is defined as a macro
(15.7.1 [<A href="https://wg21.link/cpp.replace.general">cpp.replace.general</A>]), the program is ill-formed.</INS>
Any <I>embed-prefixed-parameter</I> is conditionally-supported, with
implementation-defined semantics.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 15.2 [<A href="https://wg21.link/cpp.cond#11">cpp.cond</A>] paragraph 11 as follows:</P>

<BLOCKQUOTE>

Prior to evaluation, macro invocations in the list of preprocessing
tokens that will become the controlling constant expression are
replaced (except for those macro names modified by the defined unary
operator), just as in normal text.
<INS>If replacement of macros in the preprocessing tokens following
the sequence <TT>__has_embed (</TT> and before a matching <TT>)</TT>
(possibly produced by macro expansion) encounters a preprocessing
token that is one of the <I>identifier</I>s <TT>limit</TT>,
<TT>prefix</TT>, <TT>suffix</TT>, or <TT>if_empty</TT> and
that <I>identifier</I> is defined as a macro
(15.7.1 [<A href="https://wg21.link/cpp.replace.general">cpp.replace.general</A>]), the program is ill-formed.</INS> If the
preprocessing token <TT>defined</TT> is generated as a result of this
replacement process or use of the defined unary operator does not
match one of the two specified forms prior to macro replacement, the
behavior is undefined.

</BLOCKQUOTE>
</LI>
</OL>

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