Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8135505 | emb-9 | Kim Barrett | P4 | Resolved | Fixed | team |
The current expansion of STATIC_ASSERT is a typedef, with the same type name always used. This seemed ok because C++03 7.1.3 clause 3 says
In a given scope, a typedef specifier shall not be used to redefine
the name of any type declared in that scope to refer to a different
type. Similarly, in a given scope, a class or enumeration shall
not be declared with the same name as a typedef-name that is
declared in that scope and refers to a type other than the class or
enumeration itself.
We’re not doing that. If the assertion passes, the type will always be the same. If the assertion fails then we never get to the point of completing the typedef.
Unfortunately, 7.1.3 clause 2 says
In a given <em>non-class</em>scope, a typedef specifier can be
used to redefine the name of any type declared in that scope to
refer to the type to which it already refers.
[Emphasis mine.]
We are doing that, and we want to do it in class scope too. That clause doesn't say anything about what happens at class scope. Clause 3 doesn't forbit it though. It seems as if C++03 is simply silent about multiple typedefs for the same type in the same class scope.
Unfortunately, most of of the compilers we're using reject multiple identical typedefs in the same class scope. (Microsoft being the notable exception.)
A solution is to make the typedef'ed type name be "unique" via __LINE__ concatenation.
In a given scope, a typedef specifier shall not be used to redefine
the name of any type declared in that scope to refer to a different
type. Similarly, in a given scope, a class or enumeration shall
not be declared with the same name as a typedef-name that is
declared in that scope and refers to a type other than the class or
enumeration itself.
We’re not doing that. If the assertion passes, the type will always be the same. If the assertion fails then we never get to the point of completing the typedef.
Unfortunately, 7.1.3 clause 2 says
In a given <em>non-class</em>scope, a typedef specifier can be
used to redefine the name of any type declared in that scope to
refer to the type to which it already refers.
[Emphasis mine.]
We are doing that, and we want to do it in class scope too. That clause doesn't say anything about what happens at class scope. Clause 3 doesn't forbit it though. It seems as if C++03 is simply silent about multiple typedefs for the same type in the same class scope.
Unfortunately, most of of the compilers we're using reject multiple identical typedefs in the same class scope. (Microsoft being the notable exception.)
A solution is to make the typedef'ed type name be "unique" via __LINE__ concatenation.
- backported by
-
JDK-8135505 Multiple STATIC_ASSERTs at class scope doesn't work
-
- Resolved
-
- relates to
-
JDK-8073994 STATIC_ASSERT use of __LINE__ is wrong
-
- Resolved
-
-
JDK-8067306 Improve STATIC_ASSERT
-
- Resolved
-