Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/constexpr-union9.C

raw
1 // PR c++/120577
2 // { dg-do compile { target c++20 } }
3
4 template <class _Tp> struct optional {
5 union {
6 _Tp __val_;
7 };
8 template <class... _Args>
9 constexpr optional(_Args... __args)
10 : __val_(__args...) {}
11 };
12 template <class _Tp, class... _Args>
13 constexpr optional<_Tp> make_optional(_Args... __args) {
14 return optional<_Tp>(__args...);
15 }
16
17 struct __non_trivial_if {
18 constexpr __non_trivial_if() {}
19 };
20 struct allocator : __non_trivial_if {};
21 struct __padding {};
22 struct __short {
23 [[__no_unique_address__]] __padding __padding_;
24 int __data_;
25 };
26 struct basic_string {
27 union {
28 __short __s;
29 };
30 [[__no_unique_address__]] allocator __alloc_;
31 constexpr basic_string(int, int) {}
32 };
33 auto opt = make_optional<basic_string>(4, 'X');