Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8086027

Multiple STATIC_ASSERTs at class scope doesn't work

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • hotspot
    • None
    • b72
    • generic
    • generic

        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.

              kbarrett Kim Barrett
              kbarrett Kim Barrett
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: