[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / cxx2b-designated-initializers.cpp
blob1d9b9183b3679f186e9031d70408e1344ed5d7e9
1 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
3 namespace PR61118 {
5 union S {
6 struct {
7 int a;
8 };
9 };
11 void f(int x, auto) {
12 const S result {
13 .a = x
17 void g(void) {
18 f(0, 0);
21 } // end namespace PR61118
23 namespace GH65143 {
24 struct Inner {
25 int a;
28 struct Outer {
29 struct {
30 Inner inner;
34 template <int val> void f() {
35 constexpr Outer x{.inner = {val}};
36 static_assert(x.inner.a == val);
39 void bar() { f<4>(); }
42 namespace GH62156 {
43 union U1 {
44 int x;
45 float y;
48 struct NonTrivial {
49 NonTrivial();
50 ~NonTrivial();
53 union U2 {
54 NonTrivial x;
55 float y;
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}}