Make Atomic<T> default constructor non-explicit

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • 27
    • Affects Version/s: None
    • Component/s: hotspot

      While rewriting GC code to use Atomic<T> we have seen compilation failures like this:
      ```
      src/hotspot/share/gc/g1/g1ConcurrentMark.cpp:562:54: error: chosen constructor is explicit in copy-initialization
      make: *** [product-bundles] Error 2
        562 | ::new (&_region_mark_stats[i]) G1RegionMarkStats{};
            | ^
      src/hotspot/share/runtime/atomic.hpp:346:22: note: explicit constructor declared here
        346 | explicit constexpr Atomic(T value = 0) : SupportsArithmetic<T>(value) {}
            | ^
      src/hotspot/share/gc/g1/g1RegionMarkStatsCache.hpp:44:18: note: in implicit initialization of field '_live_words' with omitted initializer
         44 | Atomic<size_t> _live_words;
            | ^
      1 error generated.
      ```

      This case be worked around by adding a constructor G1RegionMarkStats, and explicitly initializing the atomic variable.

      It turns out that under certain conditions the `explicit` qualifier causes classes to not compile. I propose that we split the constructor into two, and only keep the `explicit` qualifier for the one-arg constructor.

            Assignee:
            Stefan Karlsson
            Reporter:
            Stefan Karlsson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: