Created on 2023-01-07.00:00:00 last changed 16 months ago
Proposed resolution (approved by CWG 2023-02-08):
Add a new bullet after 6.3 [basic.def.odr] bullet 14.8 as follows:
- In each such definition, const objects with static or thread storage duration shall be constant-initialized if the object is constant-initialized in any such definition.
- In each such definition, corresponding manifestly constant-evaluated expressions that are not value-dependent shall have the same value (7.7 [expr.const], 13.8.3.4 [temp.dep.constexpr]).
- In each such definition, the overloaded operators referred to, the implicit calls to conversion functions, constructors, operator new functions and operator delete functions, shall refer to the same function.
[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.
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-07-16 13:00:43 | admin | set | status: open -> c++23 |
2023-07-16 13:00:43 | admin | set | status: dr -> open |
2023-02-18 18:43:04 | admin | set | status: ready -> dr |
2023-02-10 23:01:52 | admin | set | status: tentatively ready -> ready |
2023-02-09 03:05:16 | admin | set | messages: + msg7179 |
2023-02-09 03:05:16 | admin | set | status: open -> tentatively ready |
2023-01-07 00:00:00 | admin | create |