Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
test/SemaCXX/address-packed.cpp
- This file was added.
// RUN: %clang_cc1 -fsyntax-only -verify %s | |||||
extern void f1(int *); | |||||
aaron.ballman: This test should only really test the parts that are different from the C test (such as… | |||||
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 { | |||||
This is unused and can be removed. aaron.ballman: This is unused and can be removed. | |||||
char c; | |||||
int x; | |||||
static void foo(); | |||||
}; | |||||
} | |||||
struct Arguable *get_arguable(); | |||||
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 | |||||
} | |||||
{ | |||||
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 { | |||||
Can we get one further test? template <typename Ty> class __attribute__((packed)) S { Ty X; public: Ty *get() const { return &X; // no warning? } }; I am fine if this does not warn. I am also fine if it only warns when there are instantiations of S for which Ty should warn (e.g., do an explicit instantiation with char that does not warn and another one with int that does). aaron.ballman: Can we get one further test?
```
template <typename Ty>
class __attribute__((packed)) S {
Ty… | |||||
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() | |||||
{ | |||||
aaron.ballmanUnsubmitted Formatting (may want to clang-format one last time before committing). aaron.ballman: Formatting (may want to clang-format one last time before committing). | |||||
S<int> s1; | |||||
s1.get(); // expected-note {{in instantiation of member function 'S<int>::get'}} | |||||
Why this->X in the diagnostic when that's not what the user wrote? aaron.ballman: Why `this->X` in the diagnostic when that's not what the user wrote? | |||||
Not Done ReplyInline ActionsProbably clang introduces it internally when parsing an id-expression that happens to be a nonstatic data member because the diagnostic does include it. That said this is going away as I'm removing the fix-it. rogfer01: Probably clang introduces it internally when parsing an id-expression that happens to be a… | |||||
S<char> s2; | |||||
s2.get(); | |||||
S<float> s3; | |||||
s3.get(); // expected-note {{in instantiation of member function 'S<float>::get'}} | |||||
} |
This test should only really test the parts that are different from the C test (such as inheritance). The goal is to have the maximum test coverage with the minimum amount of testing code.