我在模板参数中使用sizeof(),如下所示:
#include <iostream>
template<class A>
struct Foo {
A a;
};
template<class A, size_t S = sizeof(Foo<A>)>
class Bar {
public:
Bar() {
// prints 4, as expected
std::cout << sizeof(Foo<A>) << std::endl;
// prints 1! why?
std::cout << S << std::endl;
}
};
int main(int, char**) {
Bar<int> foo;
}
出于某种原因,xlc++决定将sizeof(Foo<A>)
作为默认模板参数,结果是1。为什么会这样呢?这是一个编译器错误吗?它在Visual Studio 2015中打印4、4。
我使用的是xlc版本的z/OS V2.1 XL C/C++
。
发布于 2017-01-17 22:26:25
这可能是编译器中的一个错误,该错误已在AIX上修复,但在Z上未修复
在AIX上测试最新(即ptf)版本V13.1.3预期结果V13.1预期结果V12.1预期结果V11.1预期结果
在ZOS上V2R1失败V2R2失败
如果您报告了错误,我们可以将修复程序放到V2R1中。
https://stackoverflow.com/questions/41689874
复制相似问题