This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Voted into WP at April, 2007 meeting.]
Are string literals from default argumentsused in extern inlines supposed to have the same addresses acrossall translation units?
void f(const char* = "s") inline g() { f(); }Must the "s" strings be the same in all copies of theinline function?
Steve Adamczyk:The totality of the standard's wisdom on this topic is(9.2.3 [dcl.fct.spec] paragraph 4):
A string literal in an extern inline function is the same objectin different translation units.
I'd hazard a guess that a literal in a default argument expressionis not "in" the extern inline function (it doesn't appear in thetokens of the function), and therefore it need not bethe same in different translation units.
I don't know that users would expect such strings to havethe same address, and an equally valid (and incompatible) expectationwould be that the same string literal would be used for every expansion ofa given default argument in a single translation unit.
Notes from April 2003 meeting:
The core working group feels that the address of a string literalshould be guaranteed to be the same only if it actually appearstextually within the body of the inline function. So a string ina default argument expressionin a block extern declaration inside the body of a function wouldbe the same in all instances of the function. On the otherhand, a string in a default argument expression in the header ofthe function (i.e., outside of the body) would not be the same.
Proposed resolution (April 2003):
Change the last sentence and add the note to the end of9.2.3 [dcl.fct.spec] paragraph 4:
A string literal inthe body of anextern inlinefunction is the sameobject in different translation units.[Note: A string literal that is encountered only in the context of afunction call (in the default argument expression of the called function),is not “in” theextern inline function.]
Notes from October 2003 meeting:
We discussed ctor-initializer lists and decided that they arealso part of the body. We've asked Clark Nelson to work onsyntax changes to give us a syntax term for the body of afunction so we can refer to it here. See alsoissue 452, which could use this term.
(October, 2005: moved to “review” status in concert withissue 452. With that resolution, the wordingabove needs no further changes.)
Proposed resolution (April, 2006):
Change the last sentence and add the note to the end of9.2.3 [dcl.fct.spec] paragraph 4:
A string literal inthe body of anextern inlinefunction is the same object in different translation units.[Note: A string literal appearing in a default argumentexpression is not considered to be “in the body”of an inline function merely by virtue of the expression’s use in afunction call from that inline function. —end note]