This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/64834] New: Captured variable not available in unevaluated context in a lambda with auto argument


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

            Bug ID: 64834
           Summary: Captured variable not available in unevaluated context
                    in a lambda with auto argument
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: holger.grund@ix-n.net

Created attachment 34605
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34605&action=edit
Repro

$ cat t.cpp
template <typename F>
void e(F f)
{
  f(1);
}

template <int I>
void bar() {
    int x;
    e([&] (const int& y) { (void)sizeof(x); }); // ok
    e([&] (const auto& y) { (void)sizeof(x); }); // error

}

void baz() { bar<1>(); }
$ c++ t.cpp -std=c++1y -c
t.cpp: In instantiation of âbar()::<lambda(const auto:1&)> [with auto:1 = int;
int I = 1]â:
t.cpp:4:6:   required from âvoid e(F) [with F = bar() [with int I =
1]::<lambda(const auto:1&)>]â
t.cpp:11:47:   required from âvoid bar() [with int I = 1]â
t.cpp:15:21:   required from here
t.cpp:11:41: error: âxâ was not declared in this scope
     e([&] (const auto& y) { (void)sizeof(x); }); // error
                                         ^
I don't see why x wouldn't be available in the second lambda.

File with

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]