1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2 extern void f1(int *); 3 extern void f2(char *); 4 5 struct __attribute__((packed)) Arguable { 6 int x; 7 char c; 8 static void foo(); 9 }; 10 11 extern void f3(void()); 12 13 namespace Foo { 14 struct __attribute__((packed)) Arguable { 15 char c; 16 int x; 17 static void foo(); 18 }; 19 } 20 21 struct Arguable *get_arguable(); 22 23 void f4(int &); 24 25 void to_void(void *); 26 27 template <typename... T> 28 void sink(T...); 29 g0()30void g0() { 31 { 32 Foo::Arguable arguable; 33 f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'Foo::Arguable'}} 34 f2(&arguable.c); // no-warning 35 f3(&arguable.foo); // no-warning 36 37 to_void(&arguable.x); // no-warning 38 void *p1 = &arguable.x; // no-warning 39 void *p2 = static_cast<void *>(&arguable.x); // no-warning 40 void *p3 = reinterpret_cast<void *>(&arguable.x); // no-warning 41 void *p4 = (void *)&arguable.x; // no-warning 42 sink(p1, p2, p3, p4); 43 } 44 { 45 Arguable arguable1; 46 Arguable &arguable(arguable1); 47 f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}} 48 f2(&arguable.c); // no-warning 49 f3(&arguable.foo); // no-warning 50 } 51 { 52 Arguable *arguable1; 53 Arguable *&arguable(arguable1); 54 f1(&arguable->x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}} 55 f2(&arguable->c); // no-warning 56 f3(&arguable->foo); // no-warning 57 } 58 } 59 60 struct __attribute__((packed)) A { 61 int x; 62 char c; 63 f0A64 int *f0() { 65 return &this->x; // expected-warning {{packed member 'x' of class or structure 'A'}} 66 } 67 g0A68 int *g0() { 69 return &x; // expected-warning {{packed member 'x' of class or structure 'A'}} 70 } 71 h0A72 char *h0() { 73 return &c; // no-warning 74 } 75 }; 76 77 struct B : A { f1B78 int *f1() { 79 return &this->x; // expected-warning {{packed member 'x' of class or structure 'A'}} 80 } 81 g1B82 int *g1() { 83 return &x; // expected-warning {{packed member 'x' of class or structure 'A'}} 84 } 85 h1B86 char *h1() { 87 return &c; // no-warning 88 } 89 }; 90 91 template <typename Ty> 92 class __attribute__((packed)) S { 93 Ty X; 94 95 public: get() const96 const Ty *get() const { 97 return &X; // expected-warning {{packed member 'X' of class or structure 'S<int>'}} 98 // expected-warning@-1 {{packed member 'X' of class or structure 'S<float>'}} 99 } 100 }; 101 102 template <typename Ty> 103 void h(Ty *); 104 g1()105void g1() { 106 S<int> s1; 107 s1.get(); // expected-note {{in instantiation of member function 'S<int>::get'}} 108 109 S<char> s2; 110 s2.get(); 111 112 S<float> s3; 113 s3.get(); // expected-note {{in instantiation of member function 'S<float>::get'}} 114 } 115 116 // PR35509 117 typedef long L1; 118 struct Incomplete; 119 struct S2 { 120 L1 d; 121 Incomplete *e() const; 122 } __attribute__((packed)); e() const123Incomplete *S2::e() const { return (Incomplete *)&d; } // no-warning 124