https://bugs.llvm.org/show_bug.cgi?id=49751

            Bug ID: 49751
           Summary: Explicit instantiation function template with auto
                    deduced return type fails if soft instantiation
                    occurred
           Product: clang
           Version: 11.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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 Bug #19551

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to