<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Explicit instantiation function template with auto deduced return type fails if soft instantiation occurred"
   href="https://bugs.llvm.org/show_bug.cgi?id=49751">49751</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Explicit instantiation function template with auto deduced return type fails if soft instantiation occurred
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++14
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>phalpern@halpernwightsoftware.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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: clang++ -std=c++14 -Wall -c autoreturnbug.cpp

Error produced:

autoreturnbug.cpp:4:15: error: explicit instantiation of 'f' does not refer to
a
      function template, variable template, member function, member class, or
      static data member
template auto f(int);
              ^
autoreturnbug.cpp:1:28: note: candidate template ignored: failed template
      argument deduction
template <typename T> auto f(T v) { return v; }
                           ^
1 error generated.

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 last line is valid, even with the "soft"
instantiation of `f`.

This bug might be related to <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - explicit instantiation confused for a function with a deduced return type if it's already been instantiated"
   href="show_bug.cgi?id=19551">Bug #19551</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>