I'm using sizeof() inside a template argument, like this:
#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;
}
For some reason xlc++ decides that sizeof(Foo<A>)
as the default template argument results in 1. Why is that so? is this a compiler bug? It prints 4, 4 in Visual Studio 2015.
I'm using xlc version z/OS V2.1 XL C/C++
.
Its likely a bug in the compiler which has been fixed on AIX but not on Z
Testing latest (i.e. ptf) versions on AIX V13.1.3 expected result V13.1 expected result V12.1 expected result V11.1 expected result
On ZOS V2R1 fails V2R2 fails
If you report the bug we can get the fix put into V2R1.