c++ - "Nested"带括号的类模板参数推导 : GCC vs. clang

标签 c++ templates compiler-errors language-lawyer c++17

相关但(恕我直言)不同:Nested template argument deduction for class templates not working

以下 C++17 代码被 GCC 8 拒绝,但 clang 编译它没有任何问题。 GCC 的错误消息作为注释包含在有问题的行之前。

这里哪个编译器是正确的?

https://godbolt.org/z/WG6f7G

template<class T>
struct Foo {
    Foo(T) {}
};

template<class T>
struct Bar {
     Bar(T) {};
};

void works() {
    Bar bar{1};// {}
    Foo foo(bar);// ()
}

void works_too() {
    Foo foo{Bar{1}};// {{}}
}

void error_in_gcc() {
// error: 'auto' parameter not permitted in this context
    Foo foo(Bar{1});// ({})
}

void but_this_works() {
    Foo(Bar{1});// ({})
}

最佳答案

对该问题的评论表明这是一个 GCC 错误。它已被归档为 GCC 错误报告 89062 .

关于c++ - "Nested"带括号的类模板参数推导 : GCC vs. clang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54369677/

相关文章:

C++14 从可变参数模板创建 vector

python - Python 中的 Libtcod 访问冲突错误

c++ - 将一个新 vector 推回一个 vector

c++ - 在 C++ 中,我想通过使用来自变量(例如字符串)的类型名信息从模板定义类对象

c++ - 我如何知道模板邻接列表中有哪些可用的 Boost Graph 属性?

c++ - g++ : which ways exist to find out which template specialization has been chosen by compiler?

有关 SQLException 和 RemoteException 的 Java 编译错误

c++ - C++ 中的表达式求值

haskell - 没有最后一个参数的函数组成

c++ - 错误: aggregate ‘HMAC_CTX ctx’ has incomplete type and cannot be defined