https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70124
Bug ID: 70124 Summary: alignas error in constexpr function Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Both attribute aligned and the alignas specifier are rejected with an error in a constexpr function complaining that the alignment isn't a constant expression. Attribute vector_size, on the other hand, is accepted in the same context. Note also that the diagnostic doesn't mention the value of the (constant) argument or include the call site, making it difficult to determine which invocation of the function caused the error when there is more than one. $ cat x.c && /build/gcc-trunk-bootstrap/gcc/xg++ -B /build/gcc-trunk-bootstrap/gcc -S -Wall -Wextra -Wpedantic -o/dev/null -xc++ x.c constexpr int foo (unsigned N) { typedef __attribute__ ((aligned (1 << N))) int I; I i = 0; return i; } int i = foo (__alignof__ (int)); x.c: In function ‘constexpr int foo(unsigned int)’: x.c:3:50: error: requested alignment is not an integer constant typedef __attribute__ ((aligned (1 << N))) int I; ^ $ cat x.c && /build/gcc-trunk-bootstrap/gcc/xg++ -B /build/gcc-trunk-bootstrap/gcc -S -Wall -Wextra -Wpedantic -o/dev/null -xc++ x.c constexpr int foo (unsigned N) { alignas (1 << N) int i = 0; return i; } int i = foo (__alignof__ (int)); x.c: In function ‘constexpr int foo(unsigned int)’: x.c:3:17: error: ‘N’ is not a constant expression alignas (1 << N) int i = 0; ^ x.c:3:17: error: ‘N’ is not a constant expression