unexpected invalid application of 'sizeof' to incomplete type error

Viewed 563

In the following code

#include <type_traits>

template< typename T >
struct Allocator {
    using element_type = std::aligned_storage_t< sizeof( T ) >;
};

template< typename T >
struct MPT {
    static Allocator< MPT > allocator;
};

using RV = MPT< double >;

template<>
Allocator< RV > RV::allocator = {};

g++ yields the following error: invalid application of 'sizeof' to incomplete type 'MPT'.

I tried using g++ 10.2 using Compiler Explorer (https://godbolt.org/z/ran4or). Clang and MSVC do not complain (see https://godbolt.org/z/nsE5Yj and https://godbolt.org/z/7c7n4e).

Is this really an example of an incomplete type? Which compiler is correct here?

0 Answers
Related