attributes.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
  2. namespace attribute_aligned {
  3. template<int N>
  4. struct X {
  5. char c[1] __attribute__((__aligned__((N)))); // expected-error {{alignment is not a power of 2}}
  6. };
  7. template <bool X> struct check {
  8. int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}}
  9. };
  10. template <int N> struct check_alignment {
  11. typedef check<N == sizeof(X<N>)> t; // expected-note {{in instantiation}}
  12. };
  13. check_alignment<1>::t c1;
  14. check_alignment<2>::t c2;
  15. check_alignment<3>::t c3; // expected-note 2 {{in instantiation}}
  16. check_alignment<4>::t c4;
  17. template<unsigned Size, unsigned Align>
  18. class my_aligned_storage
  19. {
  20. __attribute__((aligned(Align))) char storage[Size];
  21. };
  22. template<typename T>
  23. class C {
  24. public:
  25. C() {
  26. static_assert(sizeof(t) == sizeof(T), "my_aligned_storage size wrong");
  27. static_assert(alignof(t) == alignof(T), "my_aligned_storage align wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
  28. }
  29. private:
  30. my_aligned_storage<sizeof(T), alignof(T)> t;
  31. };
  32. C<double> cd;
  33. }
  34. namespace PR9049 {
  35. extern const void *CFRetain(const void *ref);
  36. template<typename T> __attribute__((cf_returns_retained))
  37. inline T WBCFRetain(T aValue) { return aValue ? (T)CFRetain(aValue) : (T)0; }
  38. extern void CFRelease(const void *ref);
  39. template<typename T>
  40. inline void WBCFRelease(__attribute__((cf_consumed)) T aValue) { if(aValue) CFRelease(aValue); }
  41. }