public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99799] New: Explicit instantiation function template with auto deduced return type fails if soft instantiation occurred
@ 2021-03-27 18:34 bugzilla at halpernwightsoftware dot com
  0 siblings, 0 replies; only message in thread
From: bugzilla at halpernwightsoftware dot com @ 2021-03-27 18:34 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-27 18:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-27 18:34 [Bug c++/99799] New: Explicit instantiation function template with auto deduced return type fails if soft instantiation occurred bugzilla at halpernwightsoftware dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).