<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97888>97888</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unexpected template instantiation with extern template declaration
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kamrann
</td>
</tr>
</table>
<pre>
The following is rejected by clang (and appears to have always been so). GCC accepts it.
```
template < typename T >
class Foo
{
static constexpr auto s = sizeof(T);
};
class X;
// Why does this trigger immediate instantiation?
extern template class Foo< X >;
class X
{};
template class Foo< X >;
int main () {
Foo< X > foo;
}
```
```
<source>:5:31: error: invalid application of 'sizeof' to an incomplete type 'X'
5 | static constexpr auto s = sizeof(T);
| ^~~~~~~~~
<source>:10:23: note: in instantiation of template class 'Foo<X>' requested here
10 | extern template class Foo< X >;
```
Compiler explorer: https://godbolt.org/z/qTssnz68s
Why would the `extern template` line, which is an explicit instantiation _declaration_ only, trigger the instantiation? Isn't the whole point of such a declaration to prevent unwanted instantiations?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVE1v4zYQ_TXjy2ANmrS-Djo4zqroPUVzW9DUyGJLkVqSsuMc-tsLyk5iOzm0axgQKXFm3rz3ODIEvbdENWQPkD0u5BR75-u_5eCltYuda0_1U0_YOWPcUds96oCe_iIVqcXdCZWRdo_AS2lblONI0geMDnt5IJTmKE8Bd0QWgwNeLfG37RalUjTGgDougT0C20DOLv95G2kYjYyEILYYTyNZORA-IYjv5wPKyBCwce4SXjycF4iIIcqoFSpnQ6SX0aOcosOAIB4x6FdyHfDyCXgF4uEt_PFjfZX_-e4t8AZ4g3_2J2wdBYy9Dhi93u_Jox4GanUCrW2I0kYto3YWRHMOppdI3uJ7ax8tiC0-z619jeG9w08o_3subSMOUtukE_AKbwi7jsMuba54-Uqer1-KbXCTVzRX32QgNmIFYoPkvfNpoe1BGj2bxGg1s4OuQ-DFmyxFMo60qK1yw2go0qx-OvIMvPiAnCEUW_w1teewOR6y7_9cfl_2sGIgNlwk7NZFOvdwK29q4E4G4MWZ0eeUhRfo6edEIV2Xnjy9g1ixGcT_8cUt41s3jNqQR3oZjfM0k9zHOAYQF6_uXbtzJi6d3wNvXoE3P59CsK95Ga6lTI4-usm0GHtCyNkdKMgZGm0J-BaPvVZ9GgLSzoW10vGOkx8tKSP9vPmBzppTCny7KKnE_RXB34MFXsT547F3hnB0ybSuwzCpHiVe5UwuGT0dyEac7FHaxO1NygCiWbS1aCtRyQXVq4IznosqKxd9XYm863JRrtetZLyVslq1a5WvWpJKtmq30DVnfM0Klq9WLMvKZdEJ3rWVaLuMMVZIWDMapDZLYw5DInehQ5ioroqyLBdG7siEeaBybumI80fgPM1XX6eYb7tpH2DNjA4xfGSJOhqq_7D0Mp7n67srbgk-6th_Ms4VQYvJm_rOCTr2026p3AC8SQUvj2-jd2mYA29mmAF4c27jUPN_AwAA__-xAeS0">