Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr26xx.cpp
blob8517cd5872b183dec666244c681f9e944621c670
1 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
2 // RUN: %clang_cc1 -std=c++2b -triple x86_64-unknown-unknown %s -verify
5 namespace dr2621 { // dr2621: yes
6 enum class E { a };
7 namespace One {
8 using E_t = E;
9 using enum E_t; // typedef ok
10 auto v = a;
12 namespace Two {
13 using dr2621::E;
14 int E; // we see this
15 using enum E; // expected-error {{unknown type name E}}
19 namespace dr2628 { // dr2628: no open
20 // this was reverted for the 16.x release
21 // due to regressions, see the issue for more details:
22 // https://github.com/llvm/llvm-project/issues/60777
24 template <bool A = false, bool B = false>
25 struct foo {
26 // The expected notes below should be removed when dr2628 is fully implemented again
27 constexpr foo() requires (!A && !B) = delete; // expected-note {{candidate function [with A = false, B = false]}} #DR2628_CTOR
28 constexpr foo() requires (A || B) = delete; // expected-note {{candidate function [with A = false, B = false]}}
31 void f() {
32 // The FIXME's below should be the expected errors when dr2628 is
33 // fully implemented again.
34 // FIXME-expected-error {{call to deleted}}
35 foo fooable; // expected-error {{ambiguous deduction for template arguments of 'foo'}}
36 // FIXME-expected-note@#DR2628_CTOR {{marked deleted here}}
41 namespace dr2631 { // dr2631: 16
42 constexpr int g();
43 consteval int f() {
44 return g();
46 int k(int x = f()) {
47 return x;
49 constexpr int g() {
50 return 42;
52 int test() {
53 return k();
57 namespace dr2635 { // dr2635: 16
58 template<typename T>
59 concept UnaryC = true;
60 template<typename T, typename U>
61 concept BinaryC = true;
63 struct S{ int i, j; };
64 S get_S();
66 template<typename T>
67 T get_T();
69 void use() {
70 // expected-error@+1{{decomposition declaration cannot be declared with constrained 'auto'}}
71 UnaryC auto [a, b] = get_S();
72 // expected-error@+1{{decomposition declaration cannot be declared with constrained 'auto'}}
73 BinaryC<int> auto [c, d] = get_S();
76 template<typename T>
77 void TemplUse() {
78 // expected-error@+1{{decomposition declaration cannot be declared with constrained 'auto'}}
79 UnaryC auto [a, b] = get_T<T>();
80 // expected-error@+1{{decomposition declaration cannot be declared with constrained 'auto'}}
81 BinaryC<T> auto [c, d] = get_T<T>();
85 // dr2636: na
87 namespace dr2640 { // dr2640: 16
89 int \N{Λ} = 0; //expected-error {{'Λ' is not a valid Unicode character name}} \
90 //expected-error {{expected unqualified-id}}
91 const char* emoji = "\N{🤡}"; // expected-error {{'🤡' is not a valid Unicode character name}} \
92 // expected-note 5{{did you mean}}
94 #define z(x) 0
95 #define dr2640_a z(
96 int x = dr2640_a\N{abc}); // expected-error {{'abc' is not a valid Unicode character name}}
97 int y = dr2640_a\N{LOTUS}); // expected-error {{character <U+1FAB7> not allowed in an identifier}} \
98 // expected-error {{use of undeclared identifier 'dr2640_a🪷'}} \
99 // expected-error {{extraneous ')' before ';'}}
102 // dr2642: na
104 namespace dr2644 { // dr2644: yes
106 auto z = [a = 42](int a) { // expected-error {{a lambda parameter cannot shadow an explicitly captured entity}} \
107 // expected-note {{variable 'a' is explicitly captured here}}
108 return 1;
113 #if __cplusplus >= 202302L
114 namespace dr2650 { // dr2650: yes
115 template <class T, T> struct S {};
116 template <class T> int f(S<T, T{}>*); // expected-note {{type 'X' of non-type template parameter is not a structural type}}
117 class X {
118 int m;
120 int i0 = f<X>(0); //expected-error {{no matching function for call to 'f'}}
122 #endif
124 #if __cplusplus >= 202302L
125 namespace dr2653 { // dr2653: 18
126 struct Test { void f(this const auto& = Test{}); };
127 // expected-error@-1 {{the explicit object parameter cannot have a default argument}}
128 auto L = [](this const auto& = Test{}){};
129 // expected-error@-1 {{the explicit object parameter cannot have a default argument}}
131 #endif
133 namespace dr2654 { // dr2654: 16
134 void f() {
135 int neck, tail;
136 volatile int brachiosaur;
137 brachiosaur += neck; // OK
138 brachiosaur -= neck; // OK
139 brachiosaur |= neck; // OK
143 namespace dr2681 { // dr2681: 17
144 using size_t = decltype(sizeof(int));
146 template<class T, size_t N>
147 struct H {
148 T array[N];
150 template<class T, size_t N>
151 struct I {
152 volatile T array[N];
154 template<size_t N>
155 struct J { // expected-note 3{{candidate}}
156 unsigned char array[N];
159 H h = { "abc" };
160 I i = { "def" };
161 static_assert(__is_same(decltype(h), H<char, 4>)); // Not H<const char, 4>
162 static_assert(__is_same(decltype(i), I<char, 4>));
164 J j = { "ghi" }; // expected-error {{no viable constructor or deduction guide}}
167 namespace dr2672 { // dr2672: 18 open
168 template <class T>
169 void f(T) requires requires { []() { T::invalid; } (); }; // expected-error{{type 'int' cannot be used prior to '::'}}
170 // expected-note@-1{{while substituting into a lambda expression here}}
171 // expected-note@-2{{in instantiation of requirement here}}
172 // expected-note@-3{{while substituting template arguments into constraint expression here}}
173 void f(...);
175 template <class T>
176 void bar(T) requires requires {
177 decltype([]() -> T {})::foo();
179 void bar(...);
181 void m() {
182 f(0); // expected-note {{while checking constraint satisfaction for template 'f<int>' required here}}
183 // expected-note@-1 {{in instantiation of function template specialization}}
184 bar(0);
187 #if __cplusplus >= 202302L
188 namespace dr2687 { // dr2687: 18
189 struct S{
190 void f(int);
191 static void g(int);
192 void h(this const S&, int);
195 void test() {
196 (&S::f)(1); // expected-error {{called object type 'void (dr2687::S::*)(int)' is not a function or function pointer}}
197 (&S::g)(1);
198 (&S::h)(S(), 1);
201 #endif