Issue |
97888
|
Summary |
Unexpected template instantiation with extern template declaration
|
Labels |
new issue
|
Assignees |
|
Reporter |
kamrann
|
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?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs