xref: /llvm-project/clang/test/CXX/drs/cwg12xx.cpp (revision e29c085812e259910a3d8b6c2d2f471d1c3eede4)
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
7 // RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx17,since-cxx14,since-cxx11,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors
8 
9 // cwg1200: na
10 
11 namespace cwg1213 { // cwg1213: 7
12 #if __cplusplus >= 201103L
13   using T = int[3];
14   int &&r = T{}[1];
15 
16   using T = decltype((T{}));
17   using U = decltype((T{}[2]));
18   using U = int &&;
19 
20   // Same thing but in a case where we consider overloaded operator[].
21   struct ConvertsToInt {
22     operator int();
23   };
24   struct X { int array[1]; };
25   using U = decltype(X().array[ConvertsToInt()]);
26 
27   // We apply the same rule to vector subscripting.
28   typedef int V4Int __attribute__((__vector_size__(sizeof(int) * 4)));
29   typedef int EV4Int __attribute__((__ext_vector_type__(4)));
30   using U = decltype(V4Int()[0]);
31   using U = decltype(EV4Int()[0]);
32 #endif
33 } // namespace cwg1213
34 
35 namespace cwg1223 { // cwg1223: 17
36 #if __cplusplus >= 201103L
37 struct M;
38 template <typename T>
39 struct V;
40 struct S {
41   S* operator()();
42   int N;
43   int M;
44 #if __cplusplus >= 202302L
45   template <typename T>
46   static constexpr auto V = 0;
47   void f(char);
48   void f(int);
49   void mem(S s) {
50     auto(s)()->M;
51     // since-cxx23-warning@-1 {{expression result unused}}
52     auto(s)()->V<int>;
53     // since-cxx23-warning@-1 {{expression result unused}}
54     auto(s)()->f(0);
55   }
56 #endif
57 };
58 void f(S s) {
59   {
60 #if __cplusplus >= 202302L
61     auto(s)()->N;
62     //since-cxx23-warning@-1 {{expression result unused}}
63 #endif
64     auto(s)()->M;
65   }
66   {
67     S(s)()->N;
68     // since-cxx11-warning@-1 {{expression result unused}}
69     S(s)()->M;
70     // since-cxx11-warning@-1 {{expression result unused}}
71   }
72 }
73 
74 struct A {
75     A(int*);
76     A *operator()();
77 };
78 typedef struct BB { int C[2]; } *B, C;
79 void g() {
80     A a(B ()->C);
81     A b(auto ()->C);
82     static_assert(sizeof(B ()->C[1] == sizeof(int)), "");
83     sizeof(auto () -> C[1]);
84     // since-cxx11-error@-1 {{function cannot return array type 'C[1]' (aka 'cwg1223::BB[1]')}}
85 }
86 #endif
87 } // namespace cwg1223
88 
89 namespace cwg1227 { // cwg1227: 3.0
90 #if __cplusplus >= 201103L
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(...) { }
99 
100 void h() {
101   f<int>(0); // OK, substituting return type causes deduction to fail
102   g<int>(0); // #cwg1227-g-int
103 }
104 #endif
105 } // namespace cwg1227
106 
107 namespace cwg1250 { // cwg1250: 3.9
108 struct Incomplete;
109 
110 struct Base {
111   virtual const Incomplete *meow() = 0;
112 };
113 
114 struct Derived : Base {
115   virtual Incomplete *meow();
116 };
117 } // namespace cwg1250
118 
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
128 
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
137 } // namespace cwg1265
138 
139 // cwg1291: na
140 
141 namespace cwg1295 { // cwg1295: 4
142   struct X {
143     unsigned bitfield : 4;
144   };
145 
146   X x = {1};
147 
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}}
152 
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}}
158   //   since-cxx17-note@#cwg1295-Y {{template parameter is declared here}}
159 
160 
161 #if __cplusplus >= 201103L
162   const unsigned other = 0;
163   using T = decltype(true ? other : x.bitfield);
164   using T = unsigned;
165 #endif
166 } // namespace cwg1295
167