1 // PR c++/58109 - alignas() fails to compile with constant expression 2 // { dg-do compile } 3 4 template <typename T> 5 struct Base { 6 static const int Align = sizeof (T); 7 }; 8 9 // Never instantiated. 10 template <typename T> 11 struct Derived: Base<T> 12 { 13 #if __cplusplus >= 201102L 14 // This is the meat of the (simplified) regression test for c++/58109. 15 using B = Base<T>; 16 using B::Align; 17 18 alignas (Align) char a [1]; 19 alignas (Align) T b [1]; 20 #else 21 // Fake the test for C++ 98. 22 # define Align Base<T>::Align 23 #endif 24 25 char __attribute__ ((aligned (Align))) c [1]; 26 T __attribute__ ((aligned (Align))) d [1]; 27 }; 28 29 // Instantiated to verify that the code is accepted even when instantiated. 30 template <typename T> 31 struct InstDerived: Base<T> 32 { 33 #if __cplusplus >= 201102L 34 using B = Base<T>; 35 using B::Align; 36 37 alignas (Align) char a [1]; 38 alignas (Align) T b [1]; 39 #endif 40 41 char __attribute__ ((aligned (Align))) c [1]; 42 T __attribute__ ((aligned (Align))) d [1]; 43 }; 44 45 InstDerived<int> dx; 46