【发布时间】:2021-12-26 20:58:32
【问题描述】:
以下程序使函数g<void>()上的指针x具有自动推断的返回类型:
template<class=void>
void g() {}
int main() {
auto (*x)() = &g;
(*x)();
}
程序被 GCC 接受,但在 Clang 中被拒绝并出现错误:
error: variable 'x' with type 'auto (*)()' has incompatible initializer of type '<overloaded function type>'
auto (*x)() = &g;
演示:https://gcc.godbolt.org/z/s17Mf74Wc
哪个编译器在这里?
【问题讨论】:
标签: c++ templates language-lawyer auto