为什么Clang在参数包错误中缺少默认参数? [英] Why clang missing default argument on parameter pack error?

查看:94
本文介绍了为什么Clang在参数包错误中缺少默认参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用clang(10.0.1)进行编译时:

  #include< iostream>模板< typename ... Args>无效f(int a = 4,Args& ... aArgs){std :: cout<<<<std :: endl;}int main(int argc,char * argv []){f(1、2);返回0;} 

我得到:

  main.cpp:4:30:错误:缺少参数'aArgs'的默认参数 

但是关于默认参数的标准说法:

在函数声明中,带有默认参数的参数之后,所有后续参数都必须具有来自同一范围的此声明或先前声明中提供的默认参数(自c ++ 11起)...除非从参数包扩展了参数或成为功能参数包.

这是一个叮当声的虫子?

提示:我在gcc上尝试了,效果很好

解决方案

是的,这是个错误: https://reviews.llvm.org/rGb5f2c4e45b886540 >

When I use clang (10.0.1) to compile that:

#include <iostream>

template <typename ...Args>
void f( int a = 4, Args&&... aArgs )
{
    std::cout << a << std::endl;
}

int main( int argc, char *argv[] )
{
    f( 1, 2 );
    return 0;
}

I get:

main.cpp:4:30: error: missing default argument on parameter 'aArgs'

But standard say about default arguments:

In a function declaration, after a parameter with a default argument, all subsequent parameters must have a default argument supplied in this or a previous declaration from the same scope (since c++11) ...unless the parameter was expanded from a parameter pack or be a function parameter pack.

It is a clang bug?

hint: I try it on gcc and works fine

解决方案

Yes, it's a bug: https://bugs.llvm.org/show_bug.cgi?id=23029.

It's fixed in clang 11: https://reviews.llvm.org/rGb5f2c4e45b8d54063051e6955cef0bbb7b6ab0f8

这篇关于为什么Clang在参数包错误中缺少默认参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆