[英]Clang template incomplete type
I have the following code that compiles fine under in Visual Studio and g++ but in Clang I get the error "error: 'ns::B' is an incomplete type"我有以下代码可以在 Visual Studio 和 g++ 中正常编译,但在 Clang 中我收到错误“错误:'ns::B' 是一种不完整的类型”
Ah啊
#pragma once
namespace ns
{
class B;
class A
{
friend class B;
class Inner
{
public:
int x;
Inner(int x) : x(x) {}
};
public:
template<typename T>
T getB(int i)
{
B b = B(Inner(i));
return T(b);
}
};
}
Bh乙
#pragma once
#include "A.h"
namespace ns
{
class B
{
A::Inner i;
public:
B(A::Inner i) : i(i)
{}
operator int() const
{
return i.x;
}
};
}
main.cpp主程序
#include "A.h"
#include "B.h"
int main()
{
ns::A a;
return a.getB<int>(5);
}
From my understanding the code should work because by the time the template get instantiated, B is complete.根据我的理解,代码应该可以工作,因为当模板被实例化时,B 已经完成。 Is this correct?
这样对吗? And if so, is there any way to work around the issue in Clang?
如果是这样,有什么办法可以解决 Clang 中的问题?
The program is ill-formed, no diagnostic required.该程序格式错误,无需诊断。
[temp.res]/8 : [临时文件]/8 :
The program is ill-formed, no diagnostic required, if:
程序格式错误,无需诊断,如果:
- [...]
[...]
- a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, or
由于不依赖于模板参数的构造,紧跟其定义的模板的假设实例化将是格式错误的,或
- [...]
[...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.