Created on 2015-12-09.00:00:00 last changed 33 months ago
[Accepted at the July, 2019 meeting as part of paper P1766R1 (Mitigating minor modules maladies)].
Consider:
typedef struct { void f() { extern decltype(*this) x; void *p = &x; } } X;
This forms a complete anonymous type, builds a variable of that type, which is declared, but not defined, then the variable is odr-used, then the class is given a typedef name for linkage purposes, which changes the linkage of the class and the variable.
More insidious examples can be constructed where the use of the class's linkage happens while parsing the body of the class, not one of its methods, so we can't entirely fix this by delaying the delayed parts of the class a bit longer.
It might be reasonable to expect an implementation to look ahead past the close brace for a typedef name for linkage when it sees typedef struct {, but the possibility that the typedef keyword might be after the close brace means even that would not be entirely correct.
One approach would be to make this ill-formed by fixating the linkage of the type at the point where it is used in a way that requires linkage, and giving an error when the linkage would change. Another approach would be to limit an anonymous type to the feature subset of C (no this, no member functions, no static members).
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-02-18 07:47:23 | admin | set | status: open -> cd5 |
2015-12-09 00:00:00 | admin | create |