1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5
6 namespace dr1213 { // dr1213: 7
7 #if __cplusplus >= 201103L
8 using T = int[3];
9 int &&r = T{}[1];
10
11 using T = decltype((T{}));
12 using U = decltype((T{}[2]));
13 using U = int &&;
14
15 // Same thing but in a case where we consider overloaded operator[].
16 struct ConvertsToInt {
17 operator int();
18 };
19 struct X { int array[1]; };
20 using U = decltype(X().array[ConvertsToInt()]);
21
22 // We apply the same rule to vector subscripting.
23 typedef int V4Int __attribute__((__vector_size__(sizeof(int) * 4)));
24 typedef int EV4Int __attribute__((__ext_vector_type__(4)));
25 using U = decltype(V4Int()[0]);
26 using U = decltype(EV4Int()[0]);
27 #endif
28 }
29
30 #if __cplusplus >= 201103L
31 namespace dr1227 { // dr1227: yes
32 template <class T> struct A { using X = typename T::X; }; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
33 template <class T> typename T::X f(typename A<T>::X);
f(...)34 template <class T> void f(...) { }
35 template <class T> auto g(typename A<T>::X) -> typename T::X; // expected-note {{in instantiation of template class 'dr1227::A<int>' requested here}}
g(...)36 template <class T> void g(...) { }
37
h()38 void h() {
39 f<int>(0); // OK, substituting return type causes deduction to fail
40 g<int>(0); // expected-note {{while substituting explicitly-specified template arguments into function template 'g'}}
41 }
42 }
43 #endif
44
45 namespace dr1250 { // dr1250: 3.9
46 struct Incomplete;
47
48 struct Base {
49 virtual const Incomplete *meow() = 0;
50 };
51
52 struct Derived : Base {
53 virtual Incomplete *meow();
54 };
55 }
56
57 namespace dr1265 { // dr1265: 5
58 #if __cplusplus >= 201103L
59 auto a = 0, b() -> int; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
60 auto b() -> int, d = 0; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
61 auto e() -> int, f() -> int; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
62 #endif
63
64 #if __cplusplus >= 201402L
65 auto g(), h = 0; // expected-error {{function with deduced return type must be the only declaration in its group}}
66 auto i = 0, j(); // expected-error {{function with deduced return type must be the only declaration in its group}}
67 auto k(), l(); // expected-error {{function with deduced return type must be the only declaration in its group}}
68 #endif
69 }
70
71 namespace dr1295 { // dr1295: 4
72 struct X {
73 unsigned bitfield : 4;
74 };
75
76 X x = {1};
77
78 unsigned const &r1 = static_cast<X &&>(x).bitfield; // expected-error 0-1{{C++11}}
79 unsigned const &r2 = static_cast<unsigned &&>(x.bitfield); // expected-error 0-1{{C++11}}
80
81 template<unsigned &r> struct Y {};
82 Y<x.bitfield> y;
83 #if __cplusplus <= 201402L
84 // expected-error@-2 {{does not refer to any declaration}} expected-note@-3 {{here}}
85 #else
86 // expected-error@-4 {{refers to subobject}}
87 #endif
88
89 #if __cplusplus >= 201103L
90 const unsigned other = 0;
91 using T = decltype(true ? other : x.bitfield);
92 using T = unsigned;
93 #endif
94 }
95
96