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
9 __extension__
typedef __SIZE_TYPE__
size_t;
11 template<typename T
> struct initializer_list
{
13 initializer_list(const T
*p
, size_t n
);
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]), "");
24 namespace cwg948
{ // cwg948: 3.7
25 #if __cplusplus >= 201103L
28 constexpr A(int v
) : v(v
) { }
29 constexpr operator int() const { return v
; }
34 constexpr int id(int x
)
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)) { }
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) { }
53 namespace cwg952
{ // cwg952: 2.8
56 typedef int I
; // #cwg952-I
58 struct B
: private A
{ // #cwg952-B
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}}
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}}
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}}
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}}
84 } // namespace example1
91 friend int get(B
) { return x
; }
93 } // namespace example2
96 namespace cwg960
{ // cwg960: 3.0
99 #if __cplusplus >= 201103L
100 // Check lvalue ref vs rvalue ref vs pointer.
101 virtual a
& rvalue_ref();
102 virtual a
&& lvalue_ref();
103 virtual a
& rvalue_vs_lvalue_ref(); // #cwg960-A-rvalue_vs_lvalue_ref
104 virtual a
&& lvalue_vs_rvalue_ref(); // #cwg960-A-lvalue_vs_rvalue_ref
105 virtual a
& rvalue_ref_vs_pointer(); // #cwg960-A-rvalue_ref_vs_pointer
106 virtual a
* pointer_vs_rvalue_ref(); // #cwg960-A-pointer_vs_rvalue_ref
107 virtual a
&& lvalue_ref_vs_pointer(); // #cwg960-A-lvalue_ref_vs_pointer
108 virtual a
* pointer_vs_lvalue_ref(); // #cwg960-A-pointer_vs_lvalue_ref
113 #if __cplusplus >= 201103L
114 // Check lvalue ref vs rvalue ref vs pointer.
115 a
& rvalue_ref() override
;
116 a
&& lvalue_ref() override
;
118 a
&& rvalue_vs_lvalue_ref() override
;
119 // since-cxx11-error@-1 {{virtual function 'rvalue_vs_lvalue_ref' has a different return type ('a &&') than the function it overrides (which has return type 'a &')}}
120 // since-cxx11-note@#cwg960-A-rvalue_vs_lvalue_ref {{overridden virtual function is here}}
122 a
& lvalue_vs_rvalue_ref() override
;
123 // since-cxx11-error@-1 {{virtual function 'lvalue_vs_rvalue_ref' has a different return type ('a &') than the function it overrides (which has return type 'a &&')}}
124 // since-cxx11-note@#cwg960-A-lvalue_vs_rvalue_ref {{overridden virtual function is here}}
126 a
* rvalue_ref_vs_pointer() override
;
127 // since-cxx11-error@-1 {{virtual function 'rvalue_ref_vs_pointer' has a different return type ('a *') than the function it overrides (which has return type 'a &')}}
128 // since-cxx11-note@#cwg960-A-rvalue_ref_vs_pointer {{overridden virtual function is here}}
130 a
& pointer_vs_rvalue_ref() override
;
131 // since-cxx11-error@-1 {{virtual function 'pointer_vs_rvalue_ref' has a different return type ('a &') than the function it overrides (which has return type 'a *')}}
132 // since-cxx11-note@#cwg960-A-pointer_vs_rvalue_ref {{overridden virtual function is here}}
134 a
* lvalue_ref_vs_pointer() override
;
135 // since-cxx11-error@-1 {{virtual function 'lvalue_ref_vs_pointer' has a different return type ('a *') than the function it overrides (which has return type 'a &&')}}
136 // since-cxx11-note@#cwg960-A-lvalue_ref_vs_pointer {{overridden virtual function is here}}
138 a
&& pointer_vs_lvalue_ref() override
;
139 // since-cxx11-error@-1 {{virtual function 'pointer_vs_lvalue_ref' has a different return type ('a &&') than the function it overrides (which has return type 'a *')}}
140 // since-cxx11-note@#cwg960-A-pointer_vs_lvalue_ref {{overridden virtual function is here}}
144 } // namespace cwg960
146 namespace cwg974
{ // cwg974: yes
147 #if __cplusplus >= 201103L
149 auto lam
= [](int x
= 42) { return x
; };
154 namespace cwg977
{ // cwg977: yes
155 enum E
{ e
= E() }; // #cwg977-E
156 #if !defined(_WIN32) || defined(__MINGW32__)
157 // expected-error@#cwg977-E {{invalid use of incomplete type 'E'}}
158 // expected-note@#cwg977-E {{definition of 'cwg977::E' is not complete until the closing '}'}}
160 #if __cplusplus >= 201103L
161 enum E2
: int { e2
= E2() };
162 enum struct E3
{ e
= static_cast<int>(E3()) };
163 enum struct E4
: int { e
= static_cast<int>(E4()) };
165 } // namespace cwg977
167 namespace cwg990
{ // cwg990: 3.5
168 #if __cplusplus >= 201103L
169 struct A
{ // #cwg990-A
170 A(std::initializer_list
<int>); // #cwg990-A-init-list
177 // since-cxx11-error@-1 {{no viable conversion from 'int' to 'A'}}
178 // since-cxx11-note@#cwg990-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A &' for 1st argument}}
179 // since-cxx11-note@#cwg990-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A &&' for 1st argument}}
180 // since-cxx11-note@#cwg990-A-init-list {{candidate constructor not viable: no known conversion from 'int' to 'std::initializer_list<int>' for 1st argument}}
186 C(std::initializer_list
<int>) = delete; // #cwg990-deleted
190 // since-cxx11-error@-1 {{call to deleted constructor of 'C'}}
191 // since-cxx11-note@#cwg990-deleted {{'C' has been explicitly marked deleted here}}
195 D(std::initializer_list
<int>);
196 D(std::initializer_list
<double>);