mardi 25 août 2020

Undefined reference for ~queue with explicit template instantiation with Clang 10

The following code doesn't link Clang 10 but succeed with GCC and Clang 9:

#include <queue>

template <typename T>
class A
{
public:
    void f();

private:
    std::queue<int> q;
};

template <typename T>
void A<T>::f()
{
    q = {};
}

template class A<int>;

int main()
{
    return 0;
}

What I get from the compiler is:

Online example

/opt/compiler-explorer/gcc-9.3.0/lib/gcc/x86_64-linux-gnu/9.3.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-f70f65.o: in function `A<int>::f()':

/home/ce/<source>:16: undefined reference to `std::queue<int, std::deque<int, std::allocator<int> > >::~queue()'

clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

Compiler returned: 1

It works if I replace std::queue with std::vector, std::deque or std::set; or if I remove the explicit template instantiation.

It also works if I remplace q = {} with the full constructor call q = std::queue<int>{}.

Is this code not standard or is it a compiler/libc++ bug?

Aucun commentaire:

Enregistrer un commentaire