Debian Codegraph @

clang/test/SemaCXX/cxx2b-designated-initializers.cpp

raw
1 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
2
3 namespace PR61118 {
4
5 union S {
6 struct {
7 int a;
8 };
9 };
10
11 void f(int x, auto) {
12 const S result {
13 .a = x
14 };
15 }
16
17 void g(void) {
18 f(0, 0);
19 }
20
21 } // end namespace PR61118
22
23 namespace GH65143 {
24 struct Inner {
25 int a;
26 };
27
28 struct Outer {
29 struct {
30 Inner inner;
31 };
32 };
33
34 template <int val> void f() {
35 constexpr Outer x{.inner = {val}};
36 static_assert(x.inner.a == val);
37 }
38
39 void bar() { f<4>(); }
40 }
41
42 namespace GH62156 {
43 union U1 {
44 int x;
45 float y;
46 };
47
48 struct NonTrivial {
49 NonTrivial();
50 ~NonTrivial();
51 };
52
53 union U2 {
54 NonTrivial x;
55 float y;
56 };
57
58 void f() {
59 U1 u{.x=2, // expected-note {{previous initialization is here}}
60 .y=1}; // expected-error {{initializer partially overrides prior initialization of this subobject}}
61 new U2{.x = NonTrivial{}, // expected-note {{previous initialization is here}}
62 .y=1}; // expected-error {{initializer would partially override prior initialization of object of type 'NonTrivial' with non-trivial destruction}}
63 }
64 }