7

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.

orlp
  • 112,504
  • 36
  • 218
  • 315
  • 2
    [This, perhaps?](http://comments.gmane.org/gmane.comp.gcc.bugs/425219) GCC 5.1 gives me an ICE, though. – chris Apr 26 '15 at 15:37
  • 6
    [The plot thickens...](http://coliru.stacked-crooked.com/a/3e4e9d42d7ee440a) – orlp Apr 26 '15 at 15:51

1 Answers1

1

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> {
};
Goswin von Brederlow
  • 11,875
  • 2
  • 24
  • 42