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

Improve STATIC_ASSERT

    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:
      b48
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        The present implementation of STATIC_ASSERT() (in utilities/debug.hpp) expands into a variable declaration within a do { } while (0) block.

        The use of the do/while block is to uniquify the variable name, so that it won't conflict with later uses of the macro in the same block. However, as a result of this implementation, the macro can only be used in a context where a statement is permitted. There are many use cases for static assertions that occur at global/namespace scope or class scope.

        The uniquification can instead be accomplished by splicing the __LINE__ number on to the name being declared. [The only place that won't work is if there are multiple assertions the same scope, all the result of a single macro expansion. If that situation ever arises, the way to deal with it is to add a variant assertion macro that takes an additional identifier argument.]

        Because the current implementation expands to a variable declaration, it is conditionalized for PRODUCT/non-PRODUCT, with the PRODUCT expansion being empty, e.g. no checking in PRODUCT builds, which is unfortunate.

        However, it is possible to instead use a typedef as the expansion, eliminating any code generation. This would allow checking to be done during PRODUCT builds with no runtime cost.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved: