<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 397</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="397"></A><H4>397.
  
Same address for string literals from default arguments in inline functions?
</H4>
<B>Section: </B>9.2.3&#160; [<A href="https://wg21.link/dcl.fct.spec">dcl.fct.spec</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Mark Mitchell
 &#160;&#160;&#160;

 <B>Date: </B>13 Jan 2003<BR>


<P>[Voted into WP at April, 2007 meeting.]</P>

<P>Are string literals from default arguments
used in extern inlines supposed to have the same addresses across
all translation units?</P>
<PRE>
  void f(const char* = "s")
  inline g() {
    f();
  }
</PRE>
<P>Must the "s" strings be the same in all copies of the
inline function?</P>

<P>
<U>Steve Adamczyk</U>:
The totality of the standard's wisdom on this topic is
(9.2.3 [<A href="https://wg21.link/dcl.fct.spec#4">dcl.fct.spec</A>] paragraph 4):</P>
<BLOCKQUOTE>
A string literal in an extern inline function is the same object
in different translation units.
</BLOCKQUOTE>

<P>I'd hazard a guess that a literal in a default argument expression
is not "in" the extern inline function (it doesn't appear in the
tokens of the function), and therefore it need not be
the same in different translation units.</P>

<P>I don't know that users would expect such strings to have
the same address, and an equally valid (and incompatible) expectation
would be that the same string literal would be used for every expansion of
a given default argument in a single translation unit.</P>

<P><B>Notes from April 2003 meeting:</B></P>

<P>The core working group feels that the address of a string literal
should be guaranteed to be the same only if it actually appears
textually within the body of the inline function.  So a string in
a default argument expression
in a block extern declaration inside the body of a function would
be the same in all instances of the function.  On the other
hand, a string in a default argument expression in the header of
the function (i.e., outside of the body) would not be the same.</P>

<P><B>Proposed resolution (April 2003):</B></P>

<P>Change the last sentence and add the note to the end of
9.2.3 [<A href="https://wg21.link/dcl.fct.spec#4">dcl.fct.spec</A>] paragraph 4:</P>
<BLOCKQUOTE>
A string literal in <INS>the body of</INS> an <TT>extern inline</TT>
function is the same
object in different translation units.
<INS>[<I>Note:</I> A string literal that is encountered only in the context of a
function call (in the default argument expression of the called function),
is not &#8220;in&#8221; the <TT>extern inline</TT> function.]</INS>
</BLOCKQUOTE>

<P><B>Notes from October 2003 meeting:</B></P>

<P>We discussed ctor-initializer lists and decided that they are
also part of the body.  We've asked Clark Nelson to work on
syntax changes to give us a syntax term for the body of a
function so we can refer to it here.  See also
<A HREF="452.html">issue 452</A>, which could use this term.</P>

<P><I>(October, 2005: moved to &#8220;review&#8221; status in concert with
<A HREF="452.html">issue 452</A>.  With that resolution, the wording
above needs no further changes.)</I></P>

<P><B>Proposed resolution (April, 2006):</B></P>

<P>Change the last sentence and add the note to the end of
9.2.3 [<A href="https://wg21.link/dcl.fct.spec#4">dcl.fct.spec</A>] paragraph 4:</P>

<BLOCKQUOTE>
A string literal in <INS>the body of</INS> an <TT>extern inline</TT>
function is the same object in different translation units.
<INS>[<I>Note:</I> A string literal appearing in a default argument
expression is not considered to be &#8220;in the body&#8221;
of an inline function merely by virtue of the expression&#8217;s use in a
function call from that inline function. &#8212;<I>end note</I>]</INS>
</BLOCKQUOTE>

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