gpt4 book ai didi

c++ - gcc 和 clang 在可变类模板中调用可变成员函数模板时的行为不同

转载 作者:行者123 更新时间:2023-12-04 14:05:06 25 4
gpt4 key购买 nike

下面的代码

#include <iostream>

template <class... Ts>
struct A
{
template <Ts ...Args>
static void f() {
(std::cout << ... << Args) << std::endl;
}
};

int main() {
A<int, int, int, int>::f<0, 1, 2, 3>();
}

使用 -std=c++17,使用 clang 12.0.1 编译并打印 0123,但使用 g++ 11.1 编译失败并出现以下错误:

test.cpp: In function ‘int main()’:
test.cpp:13:41: error: no matching function for call to ‘A<int, int, int, int>::f<0, 1, 2, 3>()’
13 | A<int, int, int, int>::f<0, 1, 2, 3>();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
test.cpp:7:17: note: candidate: ‘template<Ts ...Args> static void A<Ts>::f() [with Ts ...Args = {Args ...}; Ts = {int, int, int, int}]’
7 | static void f() {
| ^
test.cpp:7:17: note: template argument deduction/substitution failed:
test.cpp:13:41: error: wrong number of template arguments (4, should be 1)
13 | A<int, int, int, int>::f<0, 1, 2, 3>();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
test.cpp:7:17: note: provided for ‘template<Ts ...Args> static void A<Ts>::f() [with Ts ...Args = {Args ...}; Ts = {int, int, int, int}]’
7 | static void f() {
| ^

哪个是正确的行为?

最佳答案

这显然是一个 GCC 错误。有几个错误报告,例如 77731 , 8858091247 .它将在 GCC 12 中修复。

关于c++ - gcc 和 clang 在可变类模板中调用可变成员函数模板时的行为不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68826162/

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