Reputation: 117681
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.
Upvotes: 7
Views: 408
Reputation: 12332
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> {
};
Upvotes: 1