[英]decltype with deleted constructor is possible in template function
As I know decltype is not allowed to use deleted constructor: 据我所知,decltype不允许使用已删除的构造函数:
struct no_def
{
no_def() = delete;
};
void test()
{
decltype(no_def()) a{}; //error: use of deleted function ‘no_def::no_def()’
}
but if I make template "test" function it will compile 但如果我制作模板“测试”功能,它将编译
template<typename...>
void test()
{
decltype(no_def()) a{}; //OK
}
and it also 它也
template<typename...>
void test()
{
decltype(no_def("not", "defined", "constructor")) a{}; //OK
}
could someone explain it? 有人可以解释一下吗?
It's apparently a bug in GCC. 这显然是海湾合作委员会的一个错误。 Both the latest Clang and the latest Visual C++ correctly print a diagnostic message.
最新的Clang和最新的Visual C ++都能正确打印诊断消息。
Clang: 铛:
error: call to deleted constructor of 'no_def'
Visual C++: Visual C ++:
error C2280: 'no_def::no_def(void)': attempting to reference a deleted function
You can test this for yourself at https://godbolt.org/ . 您可以通过https://godbolt.org/自行测试。
Note that in order to verify the bug, you should simplify the template, call the function, and get rid of unused-variable warnings which interfere with the output you are interested in: 请注意,为了验证错误,您应该简化模板, 调用函数,并删除干扰您感兴趣的输出的未使用变量警告:
struct no_def
{
no_def() = delete;
};
template<typename T>
void test()
{
decltype(no_def()) a{}; // error in Clang and MSVC, no error in GCC
a = a; // get rid of warning
}
int main()
{
test<int>();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.