Why does a default argument for a lambda argument trigger a -pedantic" GCC warning?

前端 未结 3 1870
臣服心动
臣服心动 2021-02-07 05:37

I had this lambda somewhere in my code:

[](bool a, bool=true){ return !a;} }

and GCC 4.6 \"complained\" with this warning:

warn         


        
相关标签:
3条回答
  • 2021-02-07 05:54

    Since C++14 it is allowed. It was found to be a defect long time ago: Default arguments for lambdas, and also Default arguments in lambda-expressions.

    0 讨论(0)
  • 2021-02-07 05:55

    It makes no sense to have a default argument in a lambda function -- how could it ever be used? On the other hand, it does no harm, so why not allow it, after emitting a warning?

    0 讨论(0)
  • 2021-02-07 06:09

    Section 5.1.2 paragraph 5 specifically says that you can not have default values for the parameters.

    Default arguments (8.3.6) shall not be specified in the parameter-declaration-clause of a lambda-declarator.

    0 讨论(0)
提交回复
热议问题