Created on 2023-07-15.00:00:00 last changed 7 months ago
Proposed resolution (approved by CWG 2023-09-15):
Add a new paragraph in C.6.4 [diff.cpp03.dcl.dcl] as follows:
Affected subclause: 9.11 [dcl.link]
Change: Names declared in an anonymous namespace changed from external linkage to internal linkage; language linkage applies to names with external linkage only.
Rationale: Alignment with user expectations.
Effect on original feature: Valid C++ 2003 code may violate the one-definition rule (6.3 [basic.def.odr]) in this revision of C++. For example:namespace { extern "C" { extern int x; } } // #1, previously external linkage and C language linkage, now internal linkage and C++ language linkage namespace A { extern "C" int x = 42; } // #2, external linkage and C language linkage int main(void) { return x; }This code is valid in C++ 2003, but #2 is not a definition for #1 in this revision of C++, violating the one-definition rule.
[Accepted as a DR at the November, 2023 meeting.]
With C++11, anonymous namespaces changed from external linkage (with a unique namespace name) to internal linkage. That implies that extern "C", which affects names with external linkage only, no longer has an effect inside anonymous namespaces.
However, a corresponding Annex C entry is missing.
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-04-05 21:43:46 | admin | set | status: dr -> drwp |
2023-12-19 10:15:28 | admin | set | status: ready -> dr |
2023-09-15 21:51:11 | admin | set | messages: + msg7430 |
2023-09-15 21:51:11 | admin | set | status: open -> ready |
2023-07-15 00:00:00 | admin | create |