https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112867
Bug ID: 112867 Summary: extern function declaration in function scope behaves differently in template Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: a.elovikov at gmail dot com Target Milestone: --- #ifdef GOOD auto foo(int x) #else template <typename T0> auto foo(T0 x) #endif { return [](auto xs) { extern int bar(decltype(xs)); return bar(xs); }(x); } auto test(int x) { return foo(x); } Fails like this (no options, https://godbolt.org/z/1EGsK75bW): <source>: In instantiation of 'foo<int>(int)::<lambda(auto:1)> [with auto:1 = int]': <source>:11:6: required from 'auto foo(T0) [with T0 = int]' 8 | return [](auto xs) { | ~~~~~~~~~~~~~ 9 | extern int bar(decltype(xs)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | return bar(xs); | ~~~~~~~~~~~~~~~ 11 | }(x); | ~^~~ <source>:14:30: required from here 14 | auto test(int x) { return foo(x); } | ~~~^~~ <source>:10:19: error: 'bar' was not declared in this scope 10 | return bar(xs); | ~~~^~~~ Compiler returned: 1 Passes with -DGOOD (https://godbolt.org/z/dn8rzGMae).