fork download
  1. #include <cstddef>
  2.  
  3. #define alignas(...) __attribute__((__aligned__(alignof(decltype(::wheels::detail::get_type_with_alignment<__VA_ARGS__>())))))
  4.  
  5. namespace wheels {
  6. namespace detail {
  7. template <std::size_t N> struct __attribute__((__aligned__(N))) alignment_type {};
  8. template <typename T> T get_type_with_alignment();
  9. template <std::size_t N> alignment_type<N> get_type_with_alignment();
  10. }
  11. }
  12.  
  13. struct alignas(8) foo {};
  14. struct alignas(int) bar {};
  15.  
  16. struct qux {
  17. alignas(2) char frob;
  18. };
  19.  
  20. static_assert(alignof(foo) == 8, "");
  21. static_assert(alignof(bar) == alignof(int), "");
  22. static_assert(alignof(qux) == 2, "");
  23.  
  24. int main() {}
  25.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'wheels::detail::alignment_type<8u>':
prog.cpp:13:8:   instantiated from here
prog.cpp:7:88: error: requested alignment is not a constant
prog.cpp: In instantiation of 'wheels::detail::alignment_type<2u>':
prog.cpp:17:5:   instantiated from here
prog.cpp:7:88: error: requested alignment is not a constant
prog.cpp:20:1: error: static assertion failed: ""
prog.cpp:22:1: error: static assertion failed: ""
stdout
Standard output is empty