[cfe-dev] unnecessary implicit instantiation?

Troy Johnson via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 18 14:26:20 PDT 2019


Clang issues an error for the following code, whereas the GNU compiler does not.  Based on the standard, I think that an implicit instantiation should not occur because the compiler is not yet allocating an object, and that would mean that Clang is incorrectly issuing an error and GNU is correct to not issue any error.

Is my understanding correct?

> cat t.cpp
template <typename T> class A;

template <typename T>
struct B {
  static A<int> M;
};

template <typename T> A<int> B<T>::M;
> g++ -c t.cpp
> clang -c t.cpp
t.cpp:8:36: error: implicit instantiation of undefined template 'A<int>'
template <typename T> A<int> B<T>::M;
                                   ^
t.cpp:1:29: note: template is declared here
template <typename T> class A;
                            ^
1 warning and 1 error generated.


Thanks,
Troy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190918/538e68ca/attachment.html>


More information about the cfe-dev mailing list