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

2024-04-18


2678. std::source_location::current is unimplementable

Section: 6.3  [basic.def.odr]     Status: C++23     Submitter: Richard Smith     Date: 2023-01-07     Liaison: (EWG)

[Accepted as a DR at the February, 2023 meeting.]

Consider:

  #include <source_location>

  inline char *f() {
    static char array[std::source_location::current().line()];
    return array;
  }

The sequence of tokens comprising the definition of f can appear in multiple translation units, on different lines. The one-definition rule is not violated. Thus, there is a single function f in the program with a unique static local object array, but that object would have a different type in each translation unit. It is unclear how to implement this, absent the conservative approach of always returning a value-initialized object from std::source_location::current, which would defeat its purpose.

Possible approaches to resolve this issue might include:

2023-01-08

Forwarded to LWG / LEWG via cplusplus/papers#1416, by decision of the CWG chair.

EWG 2023-02-07

EWG approves of the approach for CWG2678 of changing the ODR to make use of source_location in a way that causes an inline function/function template/etc to 'be different' be an ODR violation.

Proposed resolution (approved by CWG 2023-02-08):

Add a new bullet after 6.3 [basic.def.odr] bullet 14.8 as follows: