implicit instantiation of undefined template: g++ or clang++

Viewed 39

The following code compiles with g++ and fails to compile with clang++12.

Is it an error in clang compiler or am I missing something?

// test.cpp
#include <iostream>
#include <type_traits>
#include <typeinfo>

template<class> class Class;

template<class T>
void fun()
{
    Class<T> c;
    Class<double> d;
}

template<class T>
class Class
{
public:
    Class ()
    {
        std::cout << "ctor: " << typeid(T).name() << '\n';
    }
};

int main()
{
    fun<int>();
}

Clang error:

> clang++-12 -std=c++17 test.cpp
test.cpp:13:19: error: implicit instantiation of undefined template 'Class<double>'
    Class<double> d;
                  ^
test.cpp:7:7: note: template is declared here
class Class;
      ^
1 error generated.
0 Answers
Related