Local reference to std::cout captured by lambda without asking for it

后端 未结 1 418
面向向阳花
面向向阳花 2021-01-07 16:25

Have I lost my mind? Was this always permitted?

#include 

int main()
{
    auto& os = std::cout;

    auto write = []()
    {
        os         


        
相关标签:
1条回答
  • 2021-01-07 17:18

    There's an open clang report that cover the case of implicit capture of references by lambda expressions, this is not limited to std::cout but to references variable that are found to refer to constant expressions.

    For more reference, the backing defect report on the CWG is CWG-1472

    EDIT:

    Based on @Rakete1111 comment, I should have pointed out explicitly that clang is right in accepting the code, which is the result of applying the CWG defect mentioned above. The report was reopened because of diagnosis location not because they were wrong about the acceptance

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