145
|
1 // { dg-do run }
|
|
2 // { dg-additional-options "-fstrict-aliasing" }
|
|
3
|
|
4 template <typename = void> struct Optional {
|
|
5 auto is_present() const { const bool &p = inner.present; return p; }
|
|
6 auto set_present() { if (not is_present()) inner.present = true; }
|
|
7 struct InnerType {
|
|
8 bool present = false;
|
|
9 char padding[1] = {0};
|
|
10 };
|
|
11 using inner_t = InnerType;
|
|
12 inner_t inner = {};
|
|
13 };
|
|
14
|
|
15 template <typename WrappedType> struct Wrapper {
|
|
16 auto operator-> () { return value; }
|
|
17 WrappedType *value;
|
|
18 };
|
|
19
|
|
20 void __attribute__((noipa)) foo(Optional<>& x) {}
|
|
21
|
|
22 int main()
|
|
23 {
|
|
24 Optional<> buf{};
|
|
25 foo(buf);
|
|
26 Wrapper<Optional<>> wo = {&buf};
|
|
27 wo->set_present();
|
|
28 auto x = wo->is_present();
|
|
29 if (!x)
|
|
30 __builtin_abort ();
|
|
31 }
|