I've reduced my problem to the following:
struct A {
static constexpr std::size_t f() { return 4; }
};
template<std::size_t N>
struct B : A {
alignas(A::f()) char a[N];
};
I don't see what's wrong with this, yet if I try to compile using g++
:
main.cpp:9:19: error: expression 'A::f' is not a constant-expression
alignas(A::f()) char a[N];
^
main.cpp:9: confused by earlier errors, bailing out
Reproduction is available on coliru.
I don't know why the original code is bad but here is a workaround:
struct A {
static constexpr std::size_t f() { return 4; }
};
template<std::size_t ALIGN, std::size_t N>
struct C {
alignas(ALIGN) char a[N];
};
template<std::size_t N>
struct B : A, C<A::f(), N> {
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With