https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86826
Bug ID: 86826 Summary: deduction fails on auto-returning function template Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Reduced from: https://stackoverflow.com/q/51643222/2069064 template <typename T> auto zero(T) { return 0; } template <typename F> void deduce(F); void ex() { #ifdef VAR auto x = &zero<int>; #endif #ifdef FUNC deduce(&zero<int>); #endif } Compiling with -DVAR succeds. With -DVAR -DFUNC also succeeds. But with just -DFUNC fails: <source>: In function 'void ex()': <source>:9:20: error: no matching function for call to 'deduce(<unresolved overloaded function type>)' deduce(&zero<int>); ^ <source>:2:28: note: candidate: 'template<class F> void deduce(F)' template <typename F> void deduce(F); ^~~~~~ <source>:2:28: note: template argument deduction/substitution failed: <source>:9:20: note: couldn't deduce template parameter 'F' deduce(&zero<int>); ^ Compiler returned: 1 If zero() didn't return auto (whether trailing return type or leading return type), code compiles fine. clang accepts.