https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219
Bug ID: 97219
Summary: Generic lambda does not find function declaration from
enclosing block scope
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Keywords: accepts-invalid, rejects-valid, wrong-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hstong at ca dot ibm.com
Target Milestone: ---
The unqualified lookup for `q` in the instantiation of the generic lambda
should resolve to the block-scope function declaration.
Such a lookup result should furthermore suppress argument dependent lookup.
GCC resolves `q` using argument dependent lookup at the point of instantiation
and chooses a worse candidate.
### SOURCE (<stdin>):
struct B;
template <typename T>
auto f(T *) {
void q(B *, void * = static_cast<T *>(0));
return [](auto *p) { q(p); };
}
void q(void *) = delete;
int main(void) {
B *bp = 0;
f(bp)(bp);
}
### COMPILER INVOCATION:
g++ -fsyntax-only -std=c++20 -Wall -Wextra -pedantic-errors -xc++ -
### ACTUAL OUTPUT:
<stdin>: In instantiation of 'f<B>::<lambda(auto:1*)> [with auto:1 = B]':
<stdin>:13:11: required from here
<stdin>:6:25: error: use of deleted function 'void q(void*)'
<stdin>:9:6: note: declared here
### EXPECTED OUTPUT:
(clean compile)
### 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 20200925 (experimental) (GCC)