XLC:模板化类的大小不起作用

xlc: sizeof of templated class not working

本文关键字:不起作用 XLC      更新时间:2023-10-16

我在模板参数中使用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++ .

它可能是编译器中的一个错误,该错误已在 AIX 上修复,但在 Z 上未修复

在 AIX 上测试最新(即 PTF)版本V13.1.3 预期结果V13.1 预期结果V12.1 预期结果V11.1 预期结果

在佐斯上V2R1 失败V2R2 失败

如果您报告该错误,我们可以将修复程序放入 V2R1 中。