[X86] Move getGFNICtrlMask before CTLZ/CTTZ lowering. NFC.
[llvm-project.git] / clang / test / SemaCXX / cxx1y-initializer-aggregates.cpp
blob03a6800898d18fdfc83e53db124a175e2bef504e
1 // RUN: %clang_cc1 -std=c++1y %s -verify
3 namespace in_class_init {
4 union U { char c; double d = 4.0; };
5 constexpr U u1 = U();
6 constexpr U u2 {};
7 constexpr U u3 { 'x' };
8 static_assert(u1.d == 4.0, "");
9 static_assert(u2.d == 4.0, "");
10 static_assert(u3.c == 'x', "");
12 struct A {
13 int n = 5;
14 int m = n * 3;
15 union {
16 char c;
17 double d = 4.0;
20 constexpr A a1 {};
21 constexpr A a2 { 8 };
22 constexpr A a3 { 1, 2, { 3 } };
23 constexpr A a4 { 1, 2, { .d = 3.0 } };
24 static_assert(a1.d == 4.0, "");
25 static_assert(a2.m == 24, "");
26 static_assert(a2.d == 4.0, "");
27 static_assert(a3.c == 3, "");
28 static_assert(a3.d == 4.0, ""); // expected-error {{constant expression}} expected-note {{active member 'c'}}
29 static_assert(a4.d == 3.0, "");
31 struct B {
32 int n;
33 constexpr int f() { return n * 5; }
34 int m = f();
36 B b1 {};
37 constexpr B b2 { 2 };
38 B b3 { 1, 2 };
39 static_assert(b2.m == 10, "");
41 struct C {
42 int k;
43 union {
44 int l = k; // expected-error {{invalid use of non-static}}
49 namespace nested_aggregate_init {
50 struct A {
51 int n = 5;
52 int b = n * 3;
54 struct B {
55 constexpr B(int k) : d(1.23), k(k) {}
56 // Within this aggregate, both this object's 'this' and the temporary's
57 // 'this' are used.
58 constexpr int f() const { return A{k}.b; }
59 double d;
60 int k;
62 static_assert(B(6).f() == 18, "");
65 namespace use_self {
66 struct FibTree {
67 int n;
68 FibTree *l = // expected-note {{declared here}}
69 n > 1 ? new FibTree{n-1} : &fib0; // expected-error {{default member initializer for 'l' needed}}
70 FibTree *r = // expected-note {{declared here}}
71 n > 2 ? new FibTree{n-2} : &fib0; // expected-error {{default member initializer for 'r' needed}}
72 int v = l->v + r->v;
74 static FibTree fib0;
76 FibTree FibTree::fib0{0, nullptr, nullptr, 1};
78 int fib(int n) { return FibTree{n}.v; }
81 namespace nested_union {
82 union Test1 {
83 union {
84 int inner { 42 };
86 int outer;
88 static_assert(Test1{}.inner == 42, "");
89 struct Test2 {
90 union {
91 struct {
92 int inner : 32 { 42 }; // expected-warning {{C++20 extension}}
93 int inner_no_init;
95 int outer;
98 static_assert(Test2{}.inner == 42, "");
99 static_assert(Test2{}.inner_no_init == 0, "");
100 struct Int { int x; };
101 struct Test3 {
102 int x;
103 union {
104 struct { // expected-note {{in implicit initialization}}
105 const int& y; // expected-note {{uninitialized reference member is here}}
106 int inner : 32 { 42 }; // expected-warning {{C++20 extension}}
108 int outer;
111 Test3 test3 = {1}; // expected-error {{reference member of type 'const int &' uninitialized}}
112 constexpr char f(Test3) { return 1; } // expected-note {{candidate function}}
113 constexpr char f(Int) { return 2; } // expected-note {{candidate function}}
114 // FIXME: This shouldn't be ambiguous; either we should reject the declaration
115 // of Test3, or we should exclude f(Test3) as a candidate.
116 static_assert(f({1}) == 2, ""); // expected-error {{call to 'f' is ambiguous}}