[cfe-users] implicit instantiation of undefined template; difference between g++ and clang++
David Blaikie
dblaikie at gmail.com
Thu Apr 17 08:28:25 PDT 2014
On Thu, Apr 17, 2014 at 7:31 AM, Mike Vermeulen <mevermeulen at gmail.com> wrote:
> Following is a reduced test case from parsec suite that compiles with g++
> and fails to compile with clang++ 3.4:
>
> template<class T> class MATRIX_3X3;
>
> template<class T> class DIAGONAL_MATRIX_3X3;
>
>
>
> template<class T>
>
> class SYMMETRIC_MATRIX_3X3
>
> {
>
> public:
>
> void Fast_Solve_Eigenproblem(DIAGONAL_MATRIX_3X3<T>& eigenvalues,
>
> MATRIX_3X3<T>& eigenvectors) const
>
> {
>
> DIAGONAL_MATRIX_3X3<double> eigenvalues_double;
>
> MATRIX_3X3<double> eigenvectors_double;
>
> eigenvalues = eigenvalues_double;
>
> eigenvectors = eigenvectors_double;
>
> }
>
> };
>
>
> The error messages I receive are:
>
> ./matrix.hpp: 11:33: error: implicit instantiation of undefined template
> ‘DIAGONAL_MATRIX_3X3<double>’
>
> ./matrix.hpp: 2:25: note: template is declared here
>
> ./matrix.hpp:12:24: error: implicit instantiation of undefined template
> ‘MATRIX_3X3<double>’
>
> ./matrix.hpp:1:25: note: template is declared here
>
> 2 errors generated
>
>
> Is there something I am missing - or a way to modify this code to make it
> compile with clang++?
There are many situations with templates that are "invalid, no
diagnostic required". Clang is more aggressive in many of these cases
(mostly non-dependent expressions inside templates - Clang figures
those out and evaluates them in some places GCC doesn't (I think there
are inverse cases too, where GCC rejects things Clang accepts and both
compilers are correct/allowed to do so)).
You simply have to provide the definition of that template if you want
to write out non-dependent expressions using specializations of it.
More information about the cfe-users
mailing list