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
Bug 70125 tracks the problem with the missing context of the diagnostic.
Confirmed.
Another testcase: #include <algorithm> int main() { int aa = 0; alignas(std::max(alignof(void*), alignof(int))) int bb; bb = 1; }
Dup of bug 84403 for the original testcase. (In reply to Marek Polacek from comment #3) > Another testcase: That is valid C++14 and is accepted from GCC 8.5.0, GCC 9.1.0, and GCC 10+. *** This bug has been marked as a duplicate of bug 84403 ***