[Bug c++/83136] static class template member: invalid application of ‘sizeof’ to incomplete type

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Nov 24 14:28:00 GMT 2017


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-11-24
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

namespace std
{
using size_t = decltype(sizeof(0));
template<size_t N, size_t A>
struct aligned_storage
{
  struct type {
  alignas(A) char _data[N];
  };
};
template<size_t N, size_t A>
  using aligned_storage_t = typename aligned_storage<N, A>::type;
}

template<typename T, std::size_t N>
struct Storage
{
    std::aligned_storage_t<sizeof(T), alignof(T)> data[N];
};

template<typename T>
struct PoolObj
{
    static void* operator new(std::size_t)
    {
        return &T::pool.data[0];
    }

    static void operator delete(void*, std::size_t)
    {
    }
};

template<typename T>
struct Bar : PoolObj<Bar<T>>
{
    static Storage<Bar<T>, 10> pool;
};

template<typename T>
Storage<Bar<T>, 10> Bar<T>::pool {};

int main()
{
    Bar<int>* b = new Bar<int>();
    delete b;
}

Clang and EDG accept it.


More information about the Gcc-bugs mailing list