This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

            Bug ID: 83136
           Summary: static class template member: invalid application of
                    ‘sizeof’ to incomplete type
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: steve.lorimer at gmail dot com
  Target Milestone: ---

Created attachment 42699
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42699&action=edit
example source code illustrating bug

Compiling the below example results in the following error

-----------

In instantiation of ‘struct Storage<Bar<int>, 10ul>’:
   required from ‘struct Bar<int>’
 error: invalid application of ‘sizeof’ to incomplete type ‘Bar<int>’
  std::aligned_storage_t<sizeof(T), alignof(T)> data[N];

-----------

#include <type_traits>
#include <cstddef>

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 size)
    {
        return &T::pool.data[0];
    }

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

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;

    return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]