【发布时间】:2020-12-14 08:07:51
【问题描述】:
以下代码未链接 Clang 10,但成功链接 GCC 和 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;
}
我从编译器得到的是:
/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
如果我将std::queue 替换为std::vector、std::deque 或std::set,它会起作用;或者如果我删除显式模板实例化。
如果我将 q = {} 替换为完整的构造函数调用 q = std::queue<int>{},它也可以工作。
这段代码不标准还是编译器/libc++ 错误?
【问题讨论】:
标签: c++ c++11 templates clang++