The alignas attribute fails when used with a template-dependent integer constant, as in template<typename T> struct alignas(2*sizeof(T)) foo { /* ... */ }; when gcc complains that "error: requested alignment is not an integer constant" (no problem with clang++ 3.2). In a non-templated context, this construct compiles fine.
Confirmed. Note the testcase is missing an instantiation, like just "foo<int> f;", required to show the problem.
Dodji, please take a look at this one too.
Another simple case that fails (even without instantiation) is: template<size_type size, size_type alignment> struct aligned_storage { using type = struct { alignas(alignment) unsigned char data[size]; }; }; from http://en.cppreference.com/w/cpp/types/aligned_storage The error is: error: requested alignment is not an integer constant using type = struct { alignas(alignment) unsigned char data[size]; }; ^
Fixed.
*** Bug 57210 has been marked as a duplicate of this bug. ***
The following example still fails with the current trunk GCC. Should this bug be reopened, or should I file a new one? template <int N> void test() { constexpr int N2 = N; typedef int T alignas(N2); // error: requested alignment is not an integer constant } int main() { test<4>(); return 0; }