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
10 namespace cwg1213
{ // cwg1213: 7
11 #if __cplusplus >= 201103L
15 using T
= decltype((T
{}));
16 using U
= decltype((T
{}[2]));
19 // Same thing but in a case where we consider overloaded operator[].
20 struct ConvertsToInt
{
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]);
34 #if __cplusplus >= 201103L
35 namespace cwg1223
{ // cwg1223: 17 drafting 2023-05-12
43 #if __cplusplus >= 202302L
45 static constexpr auto V
= 0;
50 // since-cxx23-warning@-1 {{expression result unused}}
52 // since-cxx23-warning@-1 {{expression result unused}}
59 #if __cplusplus >= 202302L
61 //since-cxx23-warning@-1 {{expression result unused}}
67 // since-cxx11-warning@-1 {{expression result unused}}
69 // since-cxx11-warning@-1 {{expression result unused}}
77 typedef struct BB
{ int C
[2]; } *B
, 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]')}}
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(...) { }
101 f
<int>(0); // OK, substituting return type causes deduction to fail
102 g
<int>(0); // #cwg1227-g-int
107 namespace cwg1250
{ // cwg1250: 3.9
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}}
129 #if __cplusplus >= 201402L
131 // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
133 // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
135 // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
141 namespace cwg1295
{ // cwg1295: 4
143 unsigned bitfield
: 4;
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
);