Debian Codegraph @

clang/test/CXX/drs/cwg9xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
7
8 namespace std {
9 __extension__ typedef __SIZE_TYPE__ size_t;
10
11 template<typename T> struct initializer_list {
12 const T *p; size_t n;
13 initializer_list(const T *p, size_t n);
14 };
15 }
16
17 namespace cwg930 { // cwg930: 2.7
18 #if __cplusplus >= 201103L
19 static_assert(alignof(int[]) == alignof(int), "");
20 static_assert(alignof(int[][2]) == alignof(int[2]), "");
21 #endif
22 } // namespace cwg930
23
24 namespace cwg948 { // cwg948: 3.7
25 #if __cplusplus >= 201103L
26 class A {
27 public:
28 constexpr A(int v) : v(v) { }
29 constexpr operator int() const { return v; }
30 private:
31 int v;
32 };
33
34 constexpr int id(int x)
35 {
36 return x;
37 }
38
39 void f() {
40 if (constexpr int i = id(101)) { }
41 switch (constexpr int i = id(2)) { default: break; case 2: break; }
42 for (; constexpr int i = id(0); ) { }
43 while (constexpr int i = id(0)) { }
44
45 if (constexpr A i = 101) { }
46 switch (constexpr A i = 2) { default: break; case 2: break; }
47 for (; constexpr A i = 0; ) { }
48 while (constexpr A i = 0) { }
49 }
50 #endif
51 }
52
53 namespace cwg952 { // cwg952: 2.8
54 namespace example1 {
55 struct A {
56 typedef int I; // #cwg952-I
57 };
58 struct B : private A { // #cwg952-B
59 };
60 struct C : B {
61 void f() {
62 I i1;
63 // expected-error@-1 {{'I' is a private member of 'cwg952::example1::A'}}
64 // expected-note@#cwg952-B {{constrained by private inheritance here}}
65 // expected-note@#cwg952-I {{member is declared here}}
66 }
67 I i2;
68 // expected-error@-1 {{'I' is a private member of 'cwg952::example1::A'}}
69 // expected-note@#cwg952-B {{constrained by private inheritance here}}
70 // expected-note@#cwg952-I {{member is declared here}}
71 struct D {
72 I i3;
73 // expected-error@-1 {{'I' is a private member of 'cwg952::example1::A'}}
74 // expected-note@#cwg952-B {{constrained by private inheritance here}}
75 // expected-note@#cwg952-I {{member is declared here}}
76 void g() {
77 I i4;
78 // expected-error@-1 {{'I' is a private member of 'cwg952::example1::A'}}
79 // expected-note@#cwg952-B {{constrained by private inheritance here}}
80 // expected-note@#cwg952-I {{member is declared here}}
81 }
82 };
83 };
84 } // namespace example1
85 namespace example2 {
86 struct A {
87 protected:
88 static int x;
89 };
90 struct B : A {
91 friend int get(B) { return x; }
92 };
93 } // namespace example2
94 } // namespace cwg952
95
96 namespace cwg974 { // cwg974: yes
97 #if __cplusplus >= 201103L
98 void test() {
99 auto lam = [](int x = 42) { return x; };
100 }
101 #endif
102 }
103
104 namespace cwg977 { // cwg977: yes
105 enum E { e = E() }; // #cwg977-E
106 #if !defined(_WIN32) || defined(__MINGW32__)
107 // expected-error@#cwg977-E {{invalid use of incomplete type 'E'}}
108 // expected-note@#cwg977-E {{definition of 'cwg977::E' is not complete until the closing '}'}}
109 #endif
110 #if __cplusplus >= 201103L
111 enum E2 : int { e2 = E2() };
112 enum struct E3 { e = static_cast<int>(E3()) };
113 enum struct E4 : int { e = static_cast<int>(E4()) };
114 #endif
115 } // namespace cwg977
116
117 namespace cwg990 { // cwg990: 3.5
118 #if __cplusplus >= 201103L
119 struct A { // #cwg990-A
120 A(std::initializer_list<int>); // #cwg990-A-init-list
121 };
122 struct B {
123 A a;
124 };
125 B b1 { };
126 B b2 { 1 };
127 // since-cxx11-error@-1 {{no viable conversion from 'int' to 'A'}}
128 // since-cxx11-note@#cwg990-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A &' for 1st argument}}
129 // since-cxx11-note@#cwg990-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A &&' for 1st argument}}
130 // since-cxx11-note@#cwg990-A-init-list {{candidate constructor not viable: no known conversion from 'int' to 'std::initializer_list<int>' for 1st argument}}
131 B b3 { { 1 } };
132
133 struct C {
134 C();
135 C(int);
136 C(std::initializer_list<int>) = delete; // #cwg990-deleted
137 };
138 C c1[3] { 1 }; // ok
139 C c2[3] { 1, {2} };
140 // since-cxx11-error@-1 {{call to deleted constructor of 'C'}}
141 // since-cxx11-note@#cwg990-deleted {{'C' has been explicitly marked deleted here}}
142
143 struct D {
144 D();
145 D(std::initializer_list<int>);
146 D(std::initializer_list<double>);
147 };
148 D d{};
149 #endif
150 }