Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr9xx.cpp
blobfb13ef2967f8804c6b49d8ce3995f1e860a2f607
1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
8 namespace std {
9 __extension__ typedef __SIZE_TYPE__ size_t;
11 template<typename T> struct initializer_list {
12 const T *p; size_t n;
13 initializer_list(const T *p, size_t n);
17 namespace dr948 { // dr948: 3.7
18 #if __cplusplus >= 201103L
19 class A {
20 public:
21 constexpr A(int v) : v(v) { }
22 constexpr operator int() const { return v; }
23 private:
24 int v;
27 constexpr int id(int x)
29 return x;
32 void f() {
33 if (constexpr int i = id(101)) { }
34 switch (constexpr int i = id(2)) { default: break; case 2: break; }
35 for (; constexpr int i = id(0); ) { }
36 while (constexpr int i = id(0)) { }
38 if (constexpr A i = 101) { }
39 switch (constexpr A i = 2) { default: break; case 2: break; }
40 for (; constexpr A i = 0; ) { }
41 while (constexpr A i = 0) { }
43 #endif
46 namespace dr952 { // dr952: yes
47 namespace example1 {
48 struct A {
49 typedef int I; // #dr952-typedef-decl
51 struct B : private A { // #dr952-inheritance
53 struct C : B {
54 void f() {
55 I i1; // expected-error {{private member}}
56 // expected-note@#dr952-inheritance {{constrained by private inheritance}}
57 // expected-note@#dr952-typedef-decl {{declared here}}
59 I i2; // expected-error {{private member}}
60 // expected-note@#dr952-inheritance {{constrained by private inheritance}}
61 // expected-note@#dr952-typedef-decl {{declared here}}
62 struct D {
63 I i3; // expected-error {{private member}}
64 // expected-note@#dr952-inheritance {{constrained by private inheritance}}
65 // expected-note@#dr952-typedef-decl {{declared here}}
66 void g() {
67 I i4; // expected-error {{private member}}
68 // expected-note@#dr952-inheritance {{constrained by private inheritance}}
69 // expected-note@#dr952-typedef-decl {{declared here}}
73 } // namespace example1
74 namespace example2 {
75 struct A {
76 protected:
77 static int x;
79 struct B : A {
80 friend int get(B) { return x; }
82 } // namespace example2
83 } // namespace dr952
85 namespace dr974 { // dr974: yes
86 #if __cplusplus >= 201103L
87 void test() {
88 auto lam = [](int x = 42) { return x; };
90 #endif
93 namespace dr977 { // dr977: yes
94 enum E { e = E() };
95 #if !defined(_WIN32) || defined(__MINGW32__)
96 // expected-error@-2 {{invalid use of incomplete type 'E'}}
97 // expected-note@-3 {{definition of 'dr977::E' is not complete until the closing '}'}}
98 #endif
99 #if __cplusplus >= 201103L
100 enum E2 : int { e2 = E2() };
101 enum struct E3 { e = static_cast<int>(E3()) };
102 enum struct E4 : int { e = static_cast<int>(E4()) };
103 #endif
104 } // namespace dr977
106 namespace dr990 { // dr990: 3.5
107 #if __cplusplus >= 201103L
108 struct A { // expected-note 2{{candidate}}
109 A(std::initializer_list<int>); // expected-note {{candidate}}
111 struct B {
112 A a;
114 B b1 { };
115 B b2 { 1 }; // expected-error {{no viable conversion from 'int' to 'A'}}
116 B b3 { { 1 } };
118 struct C {
119 C();
120 C(int);
121 C(std::initializer_list<int>) = delete; // expected-note {{here}}
123 C c1[3] { 1 }; // ok
124 C c2[3] { 1, {2} }; // expected-error {{call to deleted}}
126 struct D {
127 D();
128 D(std::initializer_list<int>);
129 D(std::initializer_list<double>);
131 D d{};
132 #endif