This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2766. Repeated evaluation of a string-literal may yield different objects

Section: 5.13.5  [lex.string]     Status: open     Submitter: Balog Pal     Date: 2023-07-15

Prior to the resolution of issue 1823 (incorporated into C++17), the specification required in 9.2.3 [dcl.fct.spec] paragraph 4:

A string literal in the body of an extern inline function is the same object in different translation units.

That was changed to the following specification in 5.13.5 [lex.string] paragraph 9:

Evaluating a string-literal results in a string literal object with static storage duration (6.7.6 [basic.stc]). ... whether successive evaluations of a string-literal yield the same or a different object is unspecified.

The treatment of string literal objects was harmonized with backing arrays in P2752R3 (approved in June, 2023) and issue 2753.

The rationale for the change made by issue 1823 was deviating implementation practice: Implementations do not unify string literal objects in inline functions or template instantiations across different translation units.

However, that was a silent behavior change for examples such as:

  const char *f() { return "abc"; }
  bool b = f() == f();    // guaranteed true prior to CWG1823, now unspecified

The matter should be revisited in light of this new information.