Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
27 Views

Problem with explicit template instantiation of non-pure virtual class

Hi everyone, I recently came across a linking error when using explicit template instantiation of a non-pure virtual class (see code below).

// TemplateVirtualClass.hpp
#pragma once

template <class T>
class TemplateVirtualClass
{
public:
    TemplateVirtualClass() = default;
    TemplateVirtualClass(const TemplateVirtualClass& x) = default;
    TemplateVirtualClass(TemplateVirtualClass&& x) = default;
    virtual ~TemplateVirtualClass() = default;
    TemplateVirtualClass& operator=(const TemplateVirtualClass& x) = default;
    TemplateVirtualClass& operator=(TemplateVirtualClass&& x) = default;
};

extern template class TemplateVirtualClass<int>;

// TemplateVirtualClass.cpp
#include "TemplateVirtualClass.hpp"

template class TemplateVirtualClass<int>;

// main.cpp
#include "TemplateVirtualClass.hpp"

int main(int argc, char** argv)
{
    TemplateVirtualClass<int> tvc;
    return 0;
}

When compiling with icpc 19 I have this error message:

icpcptdjtl.o:(.data._ZTV20TemplateVirtualClassIiE[_ZTV20TemplateVirtualClassIiE]+0x18): undefined reference to `TemplateVirtualClass<int>::~TemplateVirtualClass()'

Do you have any idea why ? It compiles with g++-7.

0 Kudos
4 Replies
Highlighted
Moderator
27 Views

Looks like a compiler bug. Let's look into it.

0 Kudos
Highlighted
27 Views

Viet Hoang (Intel) wrote:

Looks like a compiler bug. Let's look into it.

Hi, any news on this issue ?

 

0 Kudos
Highlighted
Moderator
27 Views

I've reported this back to our Engineer, but it hasn't been addressed. The internal number is CMPLRIL0-32191, fyi

0 Kudos
Highlighted
27 Views

Great thank you !

0 Kudos