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 std { struct type_info; } 7 8 namespace dr1902 { // dr1902: 3.7 9 struct A {}; 10 struct B { 11 B(A); 12 #if __cplusplus >= 201103L 13 // expected-note@-2 {{candidate}} 14 #endif 15 16 B() = delete; 17 #if __cplusplus < 201103L 18 // expected-error@-2 {{extension}} 19 #endif 20 21 B(const B&) // expected-note {{deleted here}} 22 #if __cplusplus >= 201103L 23 // expected-note@-2 {{candidate}} 24 #else 25 // expected-error@+2 {{extension}} 26 #endif 27 = delete; 28 29 operator A(); 30 }; 31 32 extern B b1; 33 B b2(b1); // expected-error {{call to deleted}} 34 35 #if __cplusplus >= 201103L 36 // This is ambiguous, even though calling the B(const B&) constructor would 37 // both directly and indirectly call a deleted function. 38 B b({}); // expected-error {{ambiguous}} 39 #endif 40 } 41 42 namespace dr1903 { 43 namespace A { 44 struct a {}; 45 int a; 46 namespace B { 47 int b; 48 } 49 using namespace B; 50 namespace { 51 int c; 52 } 53 namespace D { 54 int d; 55 } 56 using D::d; 57 } 58 namespace X { 59 using A::a; 60 using A::b; 61 using A::c; 62 using A::d; 63 struct a *p; 64 } 65 } 66 67 namespace dr1909 { // dr1909: yes 68 struct A { 69 template<typename T> struct A {}; // expected-error {{member 'A' has the same name as its class}} 70 }; 71 struct B { 72 template<typename T> void B() {} // expected-error {{constructor cannot have a return type}} 73 }; 74 struct C { 75 template<typename T> static int C; // expected-error {{member 'C' has the same name as its class}} expected-error 0-1{{extension}} 76 }; 77 struct D { 78 template<typename T> using D = int; // expected-error {{member 'D' has the same name as its class}} expected-error 0-1{{extension}} 79 }; 80 } 81 82 namespace dr1940 { // dr1940: yes 83 #if __cplusplus >= 201103L 84 static union { 85 static_assert(true, ""); // ok 86 static_assert(false, ""); // expected-error {{static_assert failed}} 87 }; 88 #endif 89 } 90 91 namespace dr1941 { // dr1941: 3.9 92 #if __cplusplus >= 201402L 93 template<typename X> 94 struct base { 95 template<typename T> 96 base(T a, T b, decltype(void(*T()), 0) = 0) { 97 while (a != b) (void)*a++; 98 } 99 100 template<typename T> 101 base(T a, X x, decltype(void(T(0) * 1), 0) = 0) { 102 for (T n = 0; n != a; ++n) (void)X(x); 103 } 104 }; 105 106 struct derived : base<int> { 107 using base::base; 108 }; 109 110 struct iter { 111 iter operator++(int); 112 int operator*(); 113 friend bool operator!=(iter, iter); 114 } it, end; 115 116 derived d1(it, end); 117 derived d2(42, 9); 118 #endif 119 } 120 121 namespace dr1947 { // dr1947: yes 122 #if __cplusplus >= 201402L 123 unsigned o = 0'01; // ok 124 unsigned b = 0b'01; // expected-error {{invalid digit 'b' in octal constant}} 125 unsigned x = 0x'01; // expected-error {{invalid suffix 'x'01' on integer constant}} 126 #endif 127 } 128 129 #if __cplusplus >= 201103L 130 // dr1948: yes 131 // FIXME: This diagnostic could be improved. 132 void *operator new(__SIZE_TYPE__) noexcept { return nullptr; } // expected-error{{exception specification in declaration does not match previous declaration}} 133 #endif 134 135 namespace dr1959 { // dr1959: 3.9 136 #if __cplusplus >= 201103L 137 struct b; 138 struct c; 139 struct a { 140 a() = default; 141 a(const a &) = delete; // expected-note 2{{deleted}} 142 a(const b &) = delete; // not inherited 143 a(c &&) = delete; // expected-note {{deleted}} 144 template<typename T> a(T) = delete; 145 }; 146 147 struct b : a { // expected-note {{copy constructor of 'b' is implicitly deleted because base class 'dr1959::a' has a deleted copy constructor}} 148 using a::a; 149 }; 150 151 a x; 152 b y = x; // expected-error {{deleted}} 153 b z = z; // expected-error {{deleted}} 154 155 // FIXME: It's not really clear that this matches the intent, but it's 156 // consistent with the behavior for assignment operators. 157 struct c : a { 158 using a::a; 159 c(const c &); 160 }; 161 c q(static_cast<c&&>(q)); // expected-error {{call to deleted}} 162 #endif 163 } 164 165 namespace dr1968 { // dr1968: yes 166 #if __cplusplus >= 201103L 167 static_assert(&typeid(int) == &typeid(int), ""); // expected-error{{not an integral constant expression}} 168 #endif 169 } 170 171 namespace dr1991 { // dr1991: 3.9 172 #if __cplusplus >= 201103L 173 struct A { 174 A(int, int) = delete; 175 }; 176 177 struct B : A { 178 using A::A; 179 B(int, int, int = 0); 180 }; 181 182 // FIXME: As a resolution to an open DR against P0136R1, we treat derived 183 // class constructors as better than base class constructors in the presence 184 // of ambiguity. 185 B b(0, 0); // ok, calls B constructor 186 #endif 187 } 188 189 // dr1994: dup 529 190