Title
Repeated evaluation of a string-literal may yield different objects
Status
open
Section
5.13.5 [lex.string]
Submitter
Balog Pal

Created on 2023-07-15.00:00:00 last changed 16 months ago

Messages

Date: 2023-07-15.00:00:00

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.5 [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.

History
Date User Action Args
2023-07-15 00:00:00admincreate