https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104163

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-01-21
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The deeply nested case was:

at.C:9:48: error: 'std::atomic<std::shared_ptr<int>
>{std::_Sp_atomic<std::shared_ptr<int> >{std::_Sp_atomic<std::shared_ptr<int>
>::_Atomic_count{std::__atomic_base<long unsigned int>{0}}}}' is not a constant
expression

The real problem was a member of _Sp_atomic, so everything about
std::_Sp_atomic<std::shared_ptr<int> >::_Atomic_count{std::__atomic_base<long
unsigned int>{0}} was a red herring.

Simplified:

struct atomic_base
{
  constexpr atomic_base(int i) : i(i) { }
  int i{0};
};

struct Sp_atomic
{
  struct Atomic_count
  {
    constexpr Atomic_count() = default;
    atomic_base a{0};
  };

  void* ptr;
  Atomic_count c{};
  constexpr Sp_atomic() = default;
};

struct atomic
{
  constexpr atomic() = default;
  Sp_atomic s;
};


constinit atomic a{};


mut.C:27:18: error: 'constinit' variable 'a' does not have a constant
initializer
   27 | constinit atomic a{};
      |                  ^
mut.C:27:20: error:
'atomic{Sp_atomic{Sp_atomic::Atomic_count{atomic_base{0}}}}' is not a constant
expression
   27 | constinit atomic a{};
      |                    ^
mut.C:27:20: error: 'atomic()' is not a constant expression because it refers
to an incompletely initialized variable

Reply via email to