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