“sizeof”对不完整类型错误的意外无效应用

mkl*_*uwe 10 c++ templates g++ language-lawyer

在下面的代码中

#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 = {};
Run Code Online (Sandbox Code Playgroud)

g++ 产生以下错误:“sizeof”对不完整类型“MPT”的无效应用。

我尝试使用 Compiler Explorer ( https://godbolt.org/z/ran4or )使用 g++ 10.2 。Clang 和 MSVC 不会抱怨(参见https://godbolt.org/z/nsE5Yjhttps://godbolt.org/z/7c7n4e)。

这真的是不完整类型的例子吗?哪个编译器在这里是正确的?