[llvm-bugs] [Bug 49751] New: Explicit instantiation function template with auto deduced return type fails if soft instantiation occurred
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Mar 28 12:21:02 PDT 2021
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: unassignedclangbugs at nondot.org
Reporter: phalpern at halpernwightsoftware.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210328/b99edcae/attachment.html>
More information about the llvm-bugs
mailing list