https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119239

            Bug ID: 119239
           Summary: GCC fail to reject odr-use of local constant in
                    template lambda without capture
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qurong at ios dot ac.cn
  Target Milestone: ---

GCC incorrectly accept a lambda in a template context that implicitly odr-uses
a local constant variable without capture, while Clang properly rejects it
according to C++ standard requirements. The code works in all compilers only
when removed from template context.

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 gcc didn't report the error. 

Compiler Explorer link: https://godbolt.org/z/67T68WMhs

Reply via email to