gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:42:22 25 4
gpt4 key购买 nike

相关但(恕我直言)不同: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com