Issue 131452
Summary Lambda in template context fails to implicitly capture const local variable (accepted by GCC/MSVC)
Labels new issue
Assignees
Reporter starbugs-qurong
    In a template context, when a lambda inside a function template uses a const-qualified local variable without explicit capture, Clang incorrectly rejects the code while GCC and MSVC accept it according to the C++ standard. If we replace the function template with a regular function then clang does not emit an error. 

For this program:

template<typename T> 
void f() {
    const int i = 42;
 auto k = [] {  //  Error in Clang
        return i;  // Missing capture of 'i' in template context
    }();
}

This causes an error in clang, but MSVC and GCC accept it. 

Compiler Explorer link: https://godbolt.org/z/67T68WMhs
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to