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

            Bug ID: 97097
           Summary: operator() call from lambda fails to resolve to
                    enclosing class function
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hstong at ca dot ibm.com
  Target Milestone: ---

In the code below, GCC does not appear to perform the applicable lookup in the
appropriate class scope to resolve the reference to the `operator()` in the
enclosing class.
It seems that, somehow, GCC resolved the `operator()` to the member of the
closure class, resulting in infinite recursion.


### SOURCE (<stdin>):
extern "C" int printf(const char *, ...);

struct A {
  void f();
  void operator()(int) { printf("Hello, world!"); }
};

void A::f() {
  const auto &f = [this](auto x) -> void {
    operator()(x);
  };
  f(0);
}

int main(void) {
  A a;
  a.f();
}


### COMPILER INVOCATION:
g++ -std=c++14 -Wall -Wextra -pedantic-errors -o a.out -xc++ -


### ACTUAL RUN OUTPUT:
(program abend)


### EXPECTED RUN OUTPUT:
Hello, world!


### COMPILER VERSION INFO (g++ -v):
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20200917 (experimental) (GCC)

Reply via email to