[OpenACC] Treat 'delete' as a valid clause during parsing in C++ mode
[llvm-project.git] / clang / test / CXX / drs / cwg12xx.cpp
blobcdfbc6d6726581e467ae67205321def722dd7f58
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx98-14,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors
8 // cwg1200: na
10 namespace cwg1213 { // cwg1213: 7
11 #if __cplusplus >= 201103L
12 using T = int[3];
13 int &&r = T{}[1];
15 using T = decltype((T{}));
16 using U = decltype((T{}[2]));
17 using U = int &&;
19 // Same thing but in a case where we consider overloaded operator[].
20 struct ConvertsToInt {
21 operator int();
23 struct X { int array[1]; };
24 using U = decltype(X().array[ConvertsToInt()]);
26 // We apply the same rule to vector subscripting.
27 typedef int V4Int __attribute__((__vector_size__(sizeof(int) * 4)));
28 typedef int EV4Int __attribute__((__ext_vector_type__(4)));
29 using U = decltype(V4Int()[0]);
30 using U = decltype(EV4Int()[0]);
31 #endif
34 #if __cplusplus >= 201103L
35 namespace cwg1223 { // cwg1223: 17 drafting 2023-05-12
36 struct M;
37 template <typename T>
38 struct V;
39 struct S {
40 S* operator()();
41 int N;
42 int M;
43 #if __cplusplus >= 202302L
44 template <typename T>
45 static constexpr auto V = 0;
46 void f(char);
47 void f(int);
48 void mem(S s) {
49 auto(s)()->M;
50 // since-cxx23-warning@-1 {{expression result unused}}
51 auto(s)()->V<int>;
52 // since-cxx23-warning@-1 {{expression result unused}}
53 auto(s)()->f(0);
55 #endif
57 void f(S s) {
59 #if __cplusplus >= 202302L
60 auto(s)()->N;
61 //since-cxx23-warning@-1 {{expression result unused}}
62 #endif
63 auto(s)()->M;
66 S(s)()->N;
67 // since-cxx11-warning@-1 {{expression result unused}}
68 S(s)()->M;
69 // since-cxx11-warning@-1 {{expression result unused}}
73 struct A {
74 A(int*);
75 A *operator()();
77 typedef struct BB { int C[2]; } *B, C;
78 void g() {
79 A a(B ()->C);
80 A b(auto ()->C);
81 static_assert(sizeof(B ()->C[1] == sizeof(int)), "");
82 sizeof(auto () -> C[1]);
83 // since-cxx11-error@-1 {{function cannot return array type 'C[1]' (aka 'cwg1223::BB[1]')}}
87 #endif
89 #if __cplusplus >= 201103L
90 namespace cwg1227 { // cwg1227: 3.0
91 template <class T> struct A { using X = typename T::X; };
92 // since-cxx11-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
93 // since-cxx11-note@#cwg1227-g {{in instantiation of template class 'cwg1227::A<int>' requested here}}
94 // since-cxx11-note@#cwg1227-g-int {{while substituting explicitly-specified template arguments into function template 'g'}}
95 template <class T> typename T::X f(typename A<T>::X);
96 template <class T> void f(...) { }
97 template <class T> auto g(typename A<T>::X) -> typename T::X; // #cwg1227-g
98 template <class T> void g(...) { }
100 void h() {
101 f<int>(0); // OK, substituting return type causes deduction to fail
102 g<int>(0); // #cwg1227-g-int
105 #endif
107 namespace cwg1250 { // cwg1250: 3.9
108 struct Incomplete;
110 struct Base {
111 virtual const Incomplete *meow() = 0;
114 struct Derived : Base {
115 virtual Incomplete *meow();
119 namespace cwg1265 { // cwg1265: 5
120 #if __cplusplus >= 201103L
121 auto a = 0, b() -> int;
122 // since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
123 auto b() -> int, d = 0;
124 // since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
125 auto e() -> int, f() -> int;
126 // since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
127 #endif
129 #if __cplusplus >= 201402L
130 auto g(), h = 0;
131 // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
132 auto i = 0, j();
133 // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
134 auto k(), l();
135 // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
136 #endif
139 // cwg1291: na
141 namespace cwg1295 { // cwg1295: 4
142 struct X {
143 unsigned bitfield : 4;
146 X x = {1};
148 unsigned const &r1 = static_cast<X &&>(x).bitfield;
149 // cxx98-error@-1 {{rvalue references are a C++11 extension}}
150 unsigned const &r2 = static_cast<unsigned &&>(x.bitfield);
151 // cxx98-error@-1 {{rvalue references are a C++11 extension}}
153 template<unsigned &r> struct Y {}; // #cwg1295-Y
154 Y<x.bitfield> y; // #cwg1295-y
155 // cxx98-14-error@-1 {{non-type template argument does not refer to any declaration}}
156 // cxx98-14-note@#cwg1295-Y {{template parameter is declared here}}
157 // since-cxx17-error@#cwg1295-y {{reference cannot bind to bit-field in converted constant expression}}
159 #if __cplusplus >= 201103L
160 const unsigned other = 0;
161 using T = decltype(true ? other : x.bitfield);
162 using T = unsigned;
163 #endif