<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55743>55743</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LTO][Templates]
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++,
c++14,
clang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wolfy1961
</td>
</tr>
</table>
<pre>
In the attached C++ example, when using LTO, clang instantiates a template function despite the fact that the C++14 standard says not to do so.
> clang -O2 inst.cpp -o inst
/usr/bin/ld: /tmp/inst-05d30e.o:(.data+0x0): undefined reference to `auto foo<int>(int)'
> clang -flto -O2 inst.cpp -o inst
> echo $?
0
The relevant paragraphs in a recent C++ draft are as follows. They have been in the standard since C++14.
_An explicit instantiation declaration (13.9.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._ (section 9.2.8.5 in [this draft](https://isocpp.org/files/papers/N4860.pdf)).
and
_An entity that is the subject of
an explicit instantiation declaration and that is also used in a way that would otherwise cause an implicit
instantiation (13.9.1) in the translation unit shall be the subject of an explicit instantiation definition
somewhere in the program; otherwise the program is ill-formed, no diagnostic required._ (section 13.9.2 in the draft mentioned above).
[test.zip](https://github.com/llvm/llvm-project/files/8790228/test.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE2P2zYQ_TXyhbAgU_JaOuiwu-kCBYrmsveAEkcWC4pUScqO--v7KNpZO2mDFhCo4de8mXmP01l5aX81LIzERAiiH0my14y_4GP0VUyzpoy_svNIhi1emSP77f1zXOm1wEQZH4QJSgTyTLBAuACbDYvpg7KGSfKzwkIEGEQfYIiwzq4ou4pFF1I4yby4eGYs9i2Tlnmbs6z4lBXP17H85Qq7_cxX6LyfZ7a1q309w98W7zB2ymDUMiufGYwwzRjjuW2xl2VBucVOxutciiAQR_G1yHgTTy9G0qAMCuFoIEempxhQ9lSIB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