https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99799
Bug ID: 99799 Summary: Explicit instantiation function template with auto deduced return type fails if soft instantiation occurred Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bugzilla at halpernwightsoftware dot com Target Milestone: --- Source code (4 lines, no preprocessor directives): template <typename T> auto f(T v) { return v; } extern template auto f(int); int i = f(0); template auto f(int); Compiler command line: g++ -std=c++14 -Wall -c autoreturnbug.cpp Error produced: autoreturnbug.cpp:4:15: error: template-id 'f<>' for 'auto f(int)' does not match any template declaration 4 | template auto f(int); | ^ autoreturnbug.cpp:1:28: note: candidate is: 'template<class T> auto f(T)' 1 | template <typename T> auto f(T v) { return v; } | ^ However, if line 3 (int i = f(0)) is removed, the code compiles successfully. In the C++14 standard, section [dcl.spec.auto], paragraph 15, it says: An explicit instantiation declaration (14.7.2) does not cause the instantiation of an entity declared using a placeholder type, but it also does not prevent that entity from being instantiated as needed to determine its type. [ Example: template <typename T> auto f(T t) { return t; } extern template auto f(int); // does not instantiate f<int> int (*p)(int) = f; // instantiates f<int> to determine its return type, but an explicit // instantiation definition is still required somewhere in the program — end example ] I take that to mean that the four lines above should compile.