https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109232
Bug ID: 109232 Summary: Using deduced return type in an unevaluated context leads to codegen Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rs2740 at gmail dot com Target Milestone: --- auto begin(auto&& r) { return r.begin(); } namespace { struct R { int* begin(); }; } static_assert(__is_same(decltype(begin(R())), int*)); int main() {} Even though ::begin is only used in an unevaluated context, GCC at -O0 generates code for begin<R>, leading to a warning and a failure to link (https://gcc.godbolt.org/z/cdajoP7f3): <source>:10:14: warning: 'int* {anonymous}::R::begin()' used but never defined 10 | int* begin(); | ^~~~~ /opt/compiler-explorer/gcc-trunk-20230320/bin/../lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/cc7gqEhh.o: in function `auto begin<(anonymous namespace)::R&>((anonymous namespace)::R&)': <source>:2: undefined reference to `(anonymous namespace)::R::begin()' collect2: error: ld returned 1 exit status Execution build compiler returned: 1