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

Multiple STATIC_ASSERTs at class scope doesn't work

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b72
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved: