提问人:mkluwe 提问时间:1/18/2021 最后编辑:Guillaume Racicotmkluwe 更新时间:5/9/2023 访问量:748
意外无效地将“sizeof”应用于不完整的类型错误
unexpected invalid application of 'sizeof' to incomplete type error
问:
在以下代码中
#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++ 产生以下错误:将“sizeof”应用于不完整类型“MPT”无效。
我尝试使用 Compiler Explorer (https://godbolt.org/z/ran4or) 使用 g++ 10.2。Clang 和 MSVC 不抱怨(见 https://godbolt.org/z/nsE5Yj 和 https://godbolt.org/z/7c7n4e)。
这真的是一个不完整类型的例子吗?哪个编译器在这里是正确的?
答: 暂无答案
评论
Allocator<RV>
RV
MTP
MTP
MTP
Allocator< MPT >
MPT