dr4xx.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
  2. // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
  3. // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
  4. // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
  5. // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
  6. __extension__ typedef __SIZE_TYPE__ size_t;
  7. namespace std { struct type_info; }
  8. namespace dr400 { // dr400: yes
  9. struct A { int a; struct a {}; }; // expected-note 2{{conflicting}} expected-note {{ambiguous}}
  10. struct B { int a; struct a {}; }; // expected-note 2{{target}} expected-note {{ambiguous}}
  11. struct C : A, B { using A::a; struct a b; };
  12. struct D : A, B { using A::a; using B::a; struct a b; }; // expected-error 2{{conflicts}}
  13. struct E : A, B { struct a b; }; // expected-error {{found in multiple base classes}}
  14. }
  15. namespace dr401 { // dr401: yes
  16. template<class T, class U = typename T::type> class A : public T {}; // expected-error {{protected}} expected-error 2{{private}}
  17. class B {
  18. protected:
  19. typedef int type; // expected-note {{protected}}
  20. };
  21. class C {
  22. typedef int type; // expected-note {{private}}
  23. friend class A<C>; // expected-note {{default argument}}
  24. };
  25. class D {
  26. typedef int type; // expected-note {{private}}
  27. friend class A<D, int>;
  28. };
  29. A<B> *b; // expected-note {{default argument}}
  30. // FIXME: We're missing the "in instantiation of" note for the default
  31. // argument here.
  32. A<D> *d;
  33. struct E {
  34. template<class T, class U = typename T::type> class A : public T {};
  35. };
  36. class F {
  37. typedef int type;
  38. friend class E;
  39. };
  40. E::A<F> eaf; // ok, default argument is in befriended context
  41. // FIXME: Why do we get different diagnostics in C++11 onwards here? We seem
  42. // to not treat the default template argument as a SFINAE context in C++98.
  43. template<class T, class U = typename T::type> void f(T) {}
  44. void g(B b) { f(b); }
  45. #if __cplusplus < 201103L
  46. // expected-error@-3 0-1{{extension}} expected-error@-3 {{protected}} expected-note@-3 {{instantiation}}
  47. // expected-note@-3 {{substituting}}
  48. #else
  49. // expected-error@-5 {{no matching}} expected-note@-6 {{protected}}
  50. #endif
  51. }
  52. namespace dr403 { // dr403: yes
  53. namespace A {
  54. struct S {};
  55. int f(void*);
  56. }
  57. template<typename T> struct X {};
  58. typedef struct X<A::S>::X XS;
  59. XS *p;
  60. int k = f(p); // ok, finds A::f, even though type XS is a typedef-name
  61. // referring to an elaborated-type-specifier naming a
  62. // injected-class-name, which is about as far from a
  63. // template-id as we can make it.
  64. }
  65. // dr404: na
  66. // (NB: also sup 594)
  67. namespace dr406 { // dr406: yes
  68. typedef struct {
  69. static int n; // expected-error {{static data member 'n' not allowed in anonymous struct}}
  70. } A;
  71. }
  72. namespace dr407 { // dr407: no
  73. struct S;
  74. typedef struct S S;
  75. void f() {
  76. struct S *p;
  77. {
  78. typedef struct S S; // expected-note {{here}}
  79. struct S *p; // expected-error {{refers to a typedef}}
  80. }
  81. }
  82. struct S {};
  83. namespace UsingDir {
  84. namespace A {
  85. struct S {}; // expected-note {{found}}
  86. }
  87. namespace B {
  88. typedef int S; // expected-note {{found}}
  89. }
  90. namespace C {
  91. using namespace A;
  92. using namespace B;
  93. struct S s; // expected-error {{ambiguous}}
  94. }
  95. namespace D {
  96. // FIXME: This is valid.
  97. using A::S;
  98. typedef struct S S; // expected-note {{here}}
  99. struct S s; // expected-error {{refers to a typedef}}
  100. }
  101. namespace E {
  102. // FIXME: The standard doesn't say whether this is valid.
  103. typedef A::S S;
  104. using A::S;
  105. struct S s;
  106. }
  107. namespace F {
  108. typedef A::S S; // expected-note {{here}}
  109. }
  110. // FIXME: The standard doesn't say what to do in these cases, but
  111. // our behavior should not depend on the order of the using-directives.
  112. namespace G {
  113. using namespace A;
  114. using namespace F;
  115. struct S s;
  116. }
  117. namespace H {
  118. using namespace F;
  119. using namespace A;
  120. struct S s; // expected-error {{refers to a typedef}}
  121. }
  122. }
  123. }
  124. namespace dr408 { // dr408: 3.4
  125. template<int N> void g() { int arr[N != 1 ? 1 : -1]; }
  126. template<> void g<2>() { }
  127. template<typename T> struct S {
  128. static int i[];
  129. void f();
  130. };
  131. template<typename T> int S<T>::i[] = { 1 };
  132. template<typename T> void S<T>::f() {
  133. g<sizeof (i) / sizeof (int)>();
  134. }
  135. template<> int S<int>::i[] = { 1, 2 };
  136. template void S<int>::f(); // uses g<2>(), not g<1>().
  137. template<typename T> struct R {
  138. static int arr[];
  139. void f();
  140. };
  141. template<typename T> int R<T>::arr[1];
  142. template<typename T> void R<T>::f() {
  143. int arr[sizeof(arr) != sizeof(int) ? 1 : -1];
  144. }
  145. template<> int R<int>::arr[2];
  146. template void R<int>::f();
  147. }
  148. namespace dr409 { // dr409: yes
  149. template<typename T> struct A {
  150. typedef int B;
  151. B b1;
  152. A::B b2;
  153. A<T>::B b3;
  154. A<T*>::B b4; // expected-error {{missing 'typename'}}
  155. };
  156. }
  157. namespace dr410 { // dr410: no
  158. template<class T> void f(T);
  159. void g(int);
  160. namespace M {
  161. template<class T> void h(T);
  162. template<class T> void i(T);
  163. struct A {
  164. friend void f<>(int);
  165. friend void h<>(int);
  166. friend void g(int);
  167. template<class T> void i(T);
  168. friend void i<>(int);
  169. private:
  170. static void z(); // expected-note {{private}}
  171. };
  172. template<> void h(int) { A::z(); }
  173. // FIXME: This should be ill-formed. The member A::i<> is befriended,
  174. // not this function.
  175. template<> void i(int) { A::z(); }
  176. }
  177. template<> void f(int) { M::A::z(); }
  178. void g(int) { M::A::z(); } // expected-error {{private}}
  179. }
  180. // dr412 is in its own file.
  181. namespace dr413 { // dr413: yes
  182. struct S {
  183. int a;
  184. int : 17;
  185. int b;
  186. };
  187. S s = { 1, 2, 3 }; // expected-error {{excess elements}}
  188. struct E {};
  189. struct T { // expected-note {{here}}
  190. int a;
  191. E e;
  192. int b;
  193. };
  194. T t1 = { 1, {}, 2 };
  195. T t2 = { 1, 2 }; // expected-error {{aggregate with no elements requires explicit braces}}
  196. }
  197. namespace dr414 { // dr414: dup 305
  198. struct X {};
  199. void f() {
  200. X x;
  201. struct X {};
  202. x.~X();
  203. }
  204. }
  205. namespace dr415 { // dr415: yes
  206. template<typename T> void f(T, ...) { T::error; }
  207. void f(int, int);
  208. void g() { f(0, 0); } // ok
  209. }
  210. namespace dr416 { // dr416: yes
  211. extern struct A a;
  212. int &operator+(const A&, const A&);
  213. int &k = a + a;
  214. struct A { float &operator+(A&); };
  215. float &f = a + a;
  216. }
  217. namespace dr417 { // dr417: no
  218. struct A;
  219. struct dr417::A {}; // expected-warning {{extra qualification}}
  220. struct B { struct X; };
  221. struct C : B {};
  222. struct C::X {}; // expected-error {{no struct named 'X' in 'dr417::C'}}
  223. struct B::X { struct Y; };
  224. struct C::X::Y {}; // ok!
  225. namespace N {
  226. struct D;
  227. struct E;
  228. struct F;
  229. struct H;
  230. }
  231. // FIXME: This is ill-formed.
  232. using N::D;
  233. struct dr417::D {}; // expected-warning {{extra qualification}}
  234. using namespace N;
  235. struct dr417::E {}; // expected-warning {{extra qualification}} expected-error {{no struct named 'E'}}
  236. struct N::F {};
  237. struct G;
  238. using N::H;
  239. namespace M {
  240. struct dr417::G {}; // expected-error {{namespace 'M' does not enclose}}
  241. struct dr417::H {}; // expected-error {{namespace 'M' does not enclose}}
  242. }
  243. }
  244. namespace dr420 { // dr420: yes
  245. template<typename T> struct ptr {
  246. T *operator->() const;
  247. T &operator*() const;
  248. };
  249. template<typename T, typename P> void test(P p) {
  250. p->~T();
  251. p->T::~T();
  252. (*p).~T();
  253. (*p).T::~T();
  254. }
  255. struct X {};
  256. template void test<int>(int*);
  257. template void test<int>(ptr<int>);
  258. template void test<X>(X*);
  259. template void test<X>(ptr<X>);
  260. template<typename T>
  261. void test2(T p) {
  262. p->template Y<int>::~Y<int>();
  263. p->~Y<int>();
  264. // FIXME: This is ill-formed, but this diagnostic is terrible. We should
  265. // reject this in the parser.
  266. p->template ~Y<int>(); // expected-error 2{{no member named '~typename Y<int>'}}
  267. }
  268. template<typename T> struct Y {};
  269. template void test2(Y<int>*); // expected-note {{instantiation}}
  270. template void test2(ptr<Y<int> >); // expected-note {{instantiation}}
  271. void test3(int *p, ptr<int> q) {
  272. typedef int Int;
  273. p->~Int();
  274. q->~Int();
  275. p->Int::~Int();
  276. q->Int::~Int();
  277. }
  278. #if __cplusplus >= 201103L
  279. template<typename T> using id = T;
  280. struct A { template<typename T> using id = T; };
  281. void test4(int *p, ptr<int> q) {
  282. p->~id<int>();
  283. q->~id<int>();
  284. p->id<int>::~id<int>();
  285. q->id<int>::~id<int>();
  286. p->template id<int>::~id<int>(); // expected-error {{expected unqualified-id}}
  287. q->template id<int>::~id<int>(); // expected-error {{expected unqualified-id}}
  288. p->A::template id<int>::~id<int>();
  289. q->A::template id<int>::~id<int>();
  290. }
  291. #endif
  292. }
  293. namespace dr421 { // dr421: yes
  294. struct X { X(); int n; int &r; };
  295. int *p = &X().n; // expected-error {{taking the address of a temporary}}
  296. int *q = &X().r;
  297. }
  298. namespace dr422 { // dr422: yes
  299. template<typename T, typename U> void f() {
  300. typedef T type; // expected-note {{prev}}
  301. typedef U type; // expected-error {{redef}}
  302. }
  303. template void f<int, int>();
  304. template void f<int, char>(); // expected-note {{instantiation}}
  305. }
  306. namespace dr423 { // dr423: yes
  307. template<typename T> struct X { operator T&(); };
  308. void f(X<int> x) { x += 1; }
  309. }
  310. namespace dr424 { // dr424: yes
  311. struct A {
  312. typedef int N; // expected-note {{previous}}
  313. typedef int N; // expected-error {{redefinition}}
  314. struct X;
  315. typedef X X; // expected-note {{previous}}
  316. struct X {};
  317. struct X *p;
  318. struct A::X *q;
  319. X *r;
  320. typedef X X; // expected-error {{redefinition}}
  321. };
  322. struct B {
  323. typedef int N;
  324. };
  325. struct C : B {
  326. typedef int N; // expected-note {{previous}}
  327. typedef int N; // expected-error {{redefinition}}
  328. };
  329. }
  330. namespace dr425 { // dr425: yes
  331. struct A { template<typename T> operator T() const; } a;
  332. float f = 1.0f * a; // expected-error {{ambiguous}} expected-note 5+{{built-in candidate}}
  333. template<typename T> struct is_float;
  334. template<> struct is_float<float> { typedef void type; };
  335. struct B {
  336. template<typename T, typename U = typename is_float<T>::type> operator T() const; // expected-error 0-1{{extension}}
  337. } b;
  338. float g = 1.0f * b; // ok
  339. }
  340. namespace dr427 { // dr427: yes
  341. struct B {};
  342. struct D : public B {
  343. D(B &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}}
  344. };
  345. extern D d1;
  346. B &b = d1;
  347. const D &d2 = static_cast<const D&>(b);
  348. const D &d3 = (const D&)b;
  349. const D &d4(b); // expected-error {{deleted}}
  350. }
  351. namespace dr428 { // dr428: yes
  352. template<typename T> T make();
  353. extern struct X x; // expected-note 5{{forward declaration}}
  354. void f() {
  355. throw void(); // expected-error {{cannot throw}}
  356. throw make<void*>();
  357. throw make<const volatile void*>();
  358. throw x; // expected-error {{cannot throw}}
  359. throw make<X&>(); // expected-error {{cannot throw}}
  360. throw make<X*>(); // expected-error {{cannot throw}}
  361. throw make<const volatile X&>(); // expected-error {{cannot throw}}
  362. throw make<const volatile X*>(); // expected-error {{cannot throw}}
  363. }
  364. }
  365. namespace dr429 { // dr429: yes c++11
  366. // FIXME: This rule is obviously intended to apply to C++98 as well.
  367. struct A {
  368. static void *operator new(size_t, size_t);
  369. static void operator delete(void*, size_t);
  370. } *a = new (0) A;
  371. #if __cplusplus >= 201103L
  372. // expected-error@-2 {{'new' expression with placement arguments refers to non-placement 'operator delete'}}
  373. // expected-note@-4 {{here}}
  374. #endif
  375. struct B {
  376. static void *operator new(size_t, size_t);
  377. static void operator delete(void*);
  378. static void operator delete(void*, size_t);
  379. } *b = new (0) B; // ok, second delete is not a non-placement deallocation function
  380. }
  381. namespace dr430 { // dr430: yes c++11
  382. // resolved by n2239
  383. // FIXME: This should apply in C++98 too.
  384. void f(int n) {
  385. int a[] = { n++, n++, n++ };
  386. #if __cplusplus < 201103L
  387. // expected-warning@-2 {{multiple unsequenced modifications to 'n'}}
  388. #endif
  389. }
  390. }
  391. namespace dr431 { // dr431: yes
  392. struct A {
  393. template<typename T> T *get();
  394. template<typename T> struct B {
  395. template<typename U> U *get();
  396. };
  397. };
  398. template<typename T> void f(A a) {
  399. a.get<A>()->get<T>();
  400. a.get<T>()
  401. ->get<T>(); // expected-error {{use 'template'}}
  402. a.get<T>()->template get<T>();
  403. a.A::get<T>();
  404. A::B<int> *b = a.get<A::B<int> >();
  405. b->get<int>();
  406. b->A::B<int>::get<int>();
  407. b->A::B<int>::get<T>();
  408. b->A::B<T>::get<int>(); // expected-error {{use 'template'}}
  409. b->A::B<T>::template get<int>();
  410. b->A::B<T>::get<T>(); // expected-error {{use 'template'}}
  411. b->A::B<T>::template get<T>();
  412. A::B<T> *c = a.get<A::B<T> >();
  413. c->get<int>(); // expected-error {{use 'template'}}
  414. c->template get<int>();
  415. }
  416. }
  417. namespace dr432 { // dr432: yes
  418. template<typename T> struct A {};
  419. template<typename T> struct B : A<B> {}; // expected-error {{requires template arguments}} expected-note {{declared}}
  420. template<typename T> struct C : A<C<T> > {};
  421. #if __cplusplus >= 201103L
  422. template<typename T> struct D : decltype(A<D>()) {}; // expected-error {{requires template arguments}} expected-note {{declared}}
  423. #endif
  424. }
  425. namespace dr433 { // dr433: yes
  426. template<class T> struct S {
  427. void f(union U*);
  428. };
  429. U *p;
  430. template<class T> void S<T>::f(union U*) {}
  431. S<int> s;
  432. }
  433. namespace dr434 { // dr434: yes
  434. void f() {
  435. const int ci = 0;
  436. int *pi = 0;
  437. const int *&rpci = pi; // expected-error {{cannot bind}}
  438. rpci = &ci;
  439. *pi = 1;
  440. }
  441. }
  442. // dr435: na
  443. namespace dr436 { // dr436: yes
  444. enum E { f }; // expected-note {{previous}}
  445. void f(); // expected-error {{redefinition}}
  446. }
  447. namespace dr437 { // dr437: sup 1308
  448. // This is superseded by 1308, which is in turn superseded by 1330,
  449. // which restores this rule.
  450. template<typename U> struct T : U {};
  451. struct S {
  452. void f() throw(S);
  453. void g() throw(T<S>);
  454. struct U;
  455. void h() throw(U);
  456. struct U {};
  457. };
  458. }
  459. // dr438 FIXME write a codegen test
  460. // dr439 FIXME write a codegen test
  461. // dr441 FIXME write a codegen test
  462. // dr442: sup 348
  463. // dr443: na
  464. namespace dr444 { // dr444: yes
  465. struct D;
  466. struct B { // expected-note {{candidate is the implicit copy}} expected-note 0-1 {{implicit move}}
  467. D &operator=(D &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}}
  468. };
  469. struct D : B { // expected-note {{candidate is the implicit}} expected-note 0-1 {{implicit move}}
  470. using B::operator=;
  471. } extern d;
  472. void f() {
  473. d = d; // expected-error {{deleted}}
  474. }
  475. }
  476. namespace dr445 { // dr445: yes
  477. class A { void f(); }; // expected-note {{private}}
  478. struct B {
  479. friend void A::f(); // expected-error {{private}}
  480. };
  481. }
  482. namespace dr446 { // dr446: yes
  483. struct C;
  484. struct A {
  485. A();
  486. A(const A&) = delete; // expected-error 0-1{{extension}} expected-note +{{deleted}}
  487. A(const C&);
  488. };
  489. struct C : A {};
  490. void f(A a, bool b, C c) {
  491. void(b ? a : a);
  492. b ? A() : a; // expected-error {{deleted}}
  493. b ? a : A(); // expected-error {{deleted}}
  494. b ? A() : A(); // expected-error {{deleted}}
  495. void(b ? a : c);
  496. b ? a : C(); // expected-error {{deleted}}
  497. b ? c : A(); // expected-error {{deleted}}
  498. b ? A() : C(); // expected-error {{deleted}}
  499. }
  500. }
  501. namespace dr447 { // dr447: yes
  502. struct A { int n; int a[4]; };
  503. template<int> struct U {
  504. typedef int type;
  505. template<typename V> static void h();
  506. };
  507. template<typename T> U<sizeof(T)> g(T);
  508. template<typename T, int N> void f(int n) {
  509. // ok, not type dependent
  510. g(__builtin_offsetof(A, n)).h<int>();
  511. g(__builtin_offsetof(T, n)).h<int>();
  512. // value dependent if first argument is a dependent type
  513. U<__builtin_offsetof(A, n)>::type a;
  514. U<__builtin_offsetof(T, n)>::type b; // expected-error +{{}} expected-warning 0+{{}}
  515. // as an extension, we allow the member-designator to include array indices
  516. g(__builtin_offsetof(A, a[0])).h<int>(); // expected-error {{extension}}
  517. g(__builtin_offsetof(A, a[N])).h<int>(); // expected-error {{extension}}
  518. U<__builtin_offsetof(A, a[0])>::type c; // expected-error {{extension}}
  519. U<__builtin_offsetof(A, a[N])>::type d; // expected-error {{extension}} expected-error +{{}} expected-warning 0+{{}}
  520. }
  521. }
  522. namespace dr448 { // dr448: yes
  523. template<typename T = int> void f(int); // expected-error 0-1{{extension}} expected-note {{no known conversion}}
  524. template<typename T> void g(T t) {
  525. f<T>(t); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
  526. dr448::f(t); // expected-error {{no matching function}}
  527. }
  528. template<typename T> void f(T); // expected-note {{should be declared prior to the call site}}
  529. namespace HideFromADL { struct X {}; }
  530. template void g(int); // ok
  531. template void g(HideFromADL::X); // expected-note {{instantiation of}}
  532. }
  533. // dr449: na
  534. namespace dr450 { // dr450: yes
  535. typedef int A[3];
  536. void f1(const A &);
  537. void f2(A &); // expected-note +{{not viable}}
  538. struct S { A n; };
  539. void g() {
  540. f1(S().n);
  541. f2(S().n); // expected-error {{no match}}}
  542. }
  543. #if __cplusplus >= 201103L
  544. void h() {
  545. f1(A{});
  546. f2(A{}); // expected-error {{no match}}
  547. }
  548. #endif
  549. }
  550. namespace dr451 { // dr451: yes
  551. const int a = 1 / 0; // expected-warning {{undefined}}
  552. const int b = 1 / 0; // expected-warning {{undefined}}
  553. int arr[b]; // expected-error +{{variable length arr}}
  554. }
  555. namespace dr452 { // dr452: yes
  556. struct A {
  557. int a, b, c;
  558. A *p;
  559. int f();
  560. A() : a(f()), b(this->f() + a), c(this->a), p(this) {}
  561. };
  562. }
  563. // dr454 FIXME write a codegen test
  564. namespace dr456 { // dr456: yes
  565. // sup 903 c++11
  566. const int null = 0;
  567. void *p = null;
  568. #if __cplusplus >= 201103L
  569. // expected-error@-2 {{cannot initialize}}
  570. #else
  571. // expected-warning@-4 {{null}}
  572. #endif
  573. const bool f = false;
  574. void *q = f;
  575. #if __cplusplus >= 201103L
  576. // expected-error@-2 {{cannot initialize}}
  577. #else
  578. // expected-warning@-4 {{null}}
  579. #endif
  580. }
  581. namespace dr457 { // dr457: yes
  582. const int a = 1;
  583. const volatile int b = 1;
  584. int ax[a];
  585. int bx[b]; // expected-error +{{variable length array}}
  586. enum E {
  587. ea = a,
  588. eb = b // expected-error {{not an integral constant}} expected-note {{read of volatile-qualified}}
  589. };
  590. }
  591. namespace dr458 { // dr458: no
  592. struct A {
  593. int T;
  594. int f();
  595. template<typename> int g();
  596. };
  597. template<typename> struct B : A {
  598. int f();
  599. template<typename> int g();
  600. template<typename> int h();
  601. };
  602. int A::f() {
  603. return T;
  604. }
  605. template<typename T>
  606. int A::g() {
  607. return T; // FIXME: this is invalid, it finds the template parameter
  608. }
  609. template<typename T>
  610. int B<T>::f() {
  611. return T;
  612. }
  613. template<typename T> template<typename U>
  614. int B<T>::g() {
  615. return T;
  616. }
  617. template<typename U> template<typename T>
  618. int B<U>::h() {
  619. return T; // FIXME: this is invalid, it finds the template parameter
  620. }
  621. }
  622. namespace dr460 { // dr460: yes
  623. namespace X { namespace Q { int n; } }
  624. namespace Y {
  625. using X; // expected-error {{requires a qualified name}}
  626. using dr460::X; // expected-error {{cannot refer to namespace}}
  627. using X::Q; // expected-error {{cannot refer to namespace}}
  628. }
  629. }
  630. // dr461: na
  631. // dr462 FIXME write a codegen test
  632. // dr463: na
  633. // dr464: na
  634. // dr465: na
  635. namespace dr466 { // dr466: no
  636. typedef int I;
  637. typedef const int CI;
  638. typedef volatile int VI;
  639. void f(int *a, CI *b, VI *c) {
  640. a->~I();
  641. a->~CI();
  642. a->~VI();
  643. a->I::~I();
  644. a->CI::~CI();
  645. a->VI::~VI();
  646. a->CI::~VI(); // FIXME: This is invalid; CI and VI are not the same scalar type.
  647. b->~I();
  648. b->~CI();
  649. b->~VI();
  650. b->I::~I();
  651. b->CI::~CI();
  652. b->VI::~VI();
  653. c->~I();
  654. c->~CI();
  655. c->~VI();
  656. c->I::~I();
  657. c->CI::~CI();
  658. c->VI::~VI();
  659. }
  660. }
  661. namespace dr467 { // dr467: yes
  662. int stuff();
  663. int f() {
  664. static bool done;
  665. if (done)
  666. goto later;
  667. static int k = stuff();
  668. done = true;
  669. later:
  670. return k;
  671. }
  672. int g() {
  673. goto later; // expected-error {{cannot jump}}
  674. int k = stuff(); // expected-note {{bypasses variable initialization}}
  675. later:
  676. return k;
  677. }
  678. }
  679. namespace dr468 { // dr468: yes c++11
  680. // FIXME: Should we allow this in C++98 too?
  681. template<typename> struct A {
  682. template<typename> struct B {
  683. static int C;
  684. };
  685. };
  686. int k = dr468::template A<int>::template B<char>::C;
  687. #if __cplusplus < 201103L
  688. // expected-error@-2 2{{'template' keyword outside of a template}}
  689. #endif
  690. }
  691. namespace dr469 { // dr469: no
  692. // FIXME: The core issue here didn't really answer the question. We don't
  693. // deduce 'const T' from a function or reference type in a class template...
  694. template<typename T> struct X; // expected-note 2{{here}}
  695. template<typename T> struct X<const T> {};
  696. X<int&> x; // expected-error {{undefined}}
  697. X<int()> y; // expected-error {{undefined}}
  698. // ... but we do in a function template. GCC and EDG fail deduction of 'f'
  699. // and the second 'h'.
  700. template<typename T> void f(const T *);
  701. template<typename T> void g(T *, const T * = 0);
  702. template<typename T> void h(T *) { T::error; }
  703. template<typename T> void h(const T *);
  704. void i() {
  705. f(&i);
  706. g(&i);
  707. h(&i);
  708. }
  709. }
  710. namespace dr470 { // dr470: yes
  711. template<typename T> struct A {
  712. struct B {};
  713. };
  714. template<typename T> struct C {
  715. };
  716. template struct A<int>; // expected-note {{previous}}
  717. template struct A<int>::B; // expected-error {{duplicate explicit instantiation}}
  718. // ok, instantiating C<char> doesn't instantiate base class members.
  719. template struct A<char>;
  720. template struct C<char>;
  721. }
  722. namespace dr471 { // dr471: yes
  723. struct A { int n; };
  724. struct B : private virtual A {};
  725. struct C : protected virtual A {};
  726. struct D : B, C { int f() { return n; } };
  727. struct E : private virtual A {
  728. using A::n;
  729. };
  730. struct F : E, B { int f() { return n; } };
  731. struct G : virtual A {
  732. private:
  733. using A::n; // expected-note {{here}}
  734. };
  735. struct H : B, G { int f() { return n; } }; // expected-error {{private}}
  736. }
  737. namespace dr474 { // dr474: yes
  738. namespace N {
  739. struct S {
  740. void f();
  741. };
  742. }
  743. void N::S::f() {
  744. void g(); // expected-note {{previous}}
  745. }
  746. int g();
  747. namespace N {
  748. int g(); // expected-error {{cannot be overloaded}}
  749. }
  750. }
  751. // dr475 FIXME write a codegen test
  752. namespace dr477 { // dr477: 3.5
  753. struct A {
  754. explicit A();
  755. virtual void f();
  756. };
  757. struct B {
  758. friend explicit A::A(); // expected-error {{'explicit' is invalid in friend declarations}}
  759. friend virtual void A::f(); // expected-error {{'virtual' is invalid in friend declarations}}
  760. };
  761. explicit A::A() {} // expected-error {{can only be specified inside the class definition}}
  762. virtual void A::f() {} // expected-error {{can only be specified inside the class definition}}
  763. }
  764. namespace dr478 { // dr478: yes
  765. struct A { virtual void f() = 0; }; // expected-note {{unimplemented}}
  766. void f(A *a);
  767. void f(A a[10]); // expected-error {{array of abstract class type}}
  768. }
  769. namespace dr479 { // dr479: yes
  770. struct S {
  771. S();
  772. private:
  773. S(const S&); // expected-note +{{here}}
  774. ~S(); // expected-note +{{here}}
  775. };
  776. void f() {
  777. throw S();
  778. // expected-error@-1 {{temporary of type 'dr479::S' has private destructor}}
  779. // expected-error@-2 {{calling a private constructor}}
  780. // expected-error@-3 {{exception object of type 'dr479::S' has private destructor}}
  781. #if __cplusplus < 201103L
  782. // expected-error@-5 {{C++98 requires an accessible copy constructor}}
  783. #endif
  784. }
  785. void g() {
  786. S s; // expected-error {{private destructor}}}
  787. throw s;
  788. // expected-error@-1 {{calling a private constructor}}
  789. // expected-error@-2 {{exception object of type 'dr479::S' has private destructor}}
  790. }
  791. void h() {
  792. try {
  793. f();
  794. g();
  795. } catch (S s) {
  796. // expected-error@-1 {{calling a private constructor}}
  797. // expected-error@-2 {{variable of type 'dr479::S' has private destructor}}
  798. }
  799. }
  800. }
  801. namespace dr480 { // dr480: yes
  802. struct A { int n; };
  803. struct B : A {};
  804. struct C : virtual B {};
  805. struct D : C {};
  806. int A::*a = &A::n;
  807. int D::*b = a; // expected-error {{virtual base}}
  808. extern int D::*c;
  809. int A::*d = static_cast<int A::*>(c); // expected-error {{virtual base}}
  810. D *e;
  811. A *f = e;
  812. D *g = static_cast<D*>(f); // expected-error {{virtual base}}
  813. extern D &i;
  814. A &j = i;
  815. D &k = static_cast<D&>(j); // expected-error {{virtual base}}
  816. }
  817. namespace dr481 { // dr481: yes
  818. template<class T, T U> class A { T *x; };
  819. T *x; // expected-error {{unknown type}}
  820. template<class T *U> class B { T *x; };
  821. T *y; // ok
  822. struct C {
  823. template<class T> void f(class D *p);
  824. };
  825. D *z; // ok
  826. template<typename A = C, typename C = A> struct E {
  827. void f() {
  828. typedef ::dr481::C c; // expected-note {{previous}}
  829. typedef C c; // expected-error {{different type}}
  830. }
  831. };
  832. template struct E<>; // ok
  833. template struct E<int>; // expected-note {{instantiation of}}
  834. template<template<typename U_no_typo_correction> class A,
  835. A<int> *B,
  836. U_no_typo_correction *C> // expected-error {{unknown type}}
  837. struct F {
  838. U_no_typo_correction *x; // expected-error {{unknown type}}
  839. };
  840. template<template<class H *> class> struct G {
  841. H *x;
  842. };
  843. H *q;
  844. typedef int N;
  845. template<N X, typename N, template<N Y> class T> struct I;
  846. template<char*> struct J;
  847. I<123, char*, J> *j;
  848. }
  849. namespace dr482 { // dr482: 3.5
  850. extern int a;
  851. void f();
  852. int dr482::a = 0; // expected-warning {{extra qualification}}
  853. void dr482::f() {} // expected-warning {{extra qualification}}
  854. inline namespace X { // expected-error 0-1{{C++11 feature}}
  855. extern int b;
  856. void g();
  857. struct S;
  858. }
  859. int dr482::b = 0; // expected-warning {{extra qualification}}
  860. void dr482::g() {} // expected-warning {{extra qualification}}
  861. struct dr482::S {}; // expected-warning {{extra qualification}}
  862. void dr482::f(); // expected-warning {{extra qualification}}
  863. void dr482::g(); // expected-warning {{extra qualification}}
  864. // FIXME: The following are valid in DR482's wording, but these are bugs in
  865. // the wording which we deliberately don't implement.
  866. namespace N { typedef int type; }
  867. typedef int N::type; // expected-error {{typedef declarator cannot be qualified}}
  868. struct A {
  869. struct B;
  870. struct A::B {}; // expected-error {{extra qualification}}
  871. #if __cplusplus >= 201103L
  872. enum class C;
  873. enum class A::C {}; // expected-error {{extra qualification}}
  874. #endif
  875. };
  876. }
  877. namespace dr483 { // dr483: yes
  878. namespace climits {
  879. int check1[__SCHAR_MAX__ >= 127 ? 1 : -1];
  880. int check2[__SHRT_MAX__ >= 32767 ? 1 : -1];
  881. int check3[__INT_MAX__ >= 32767 ? 1 : -1];
  882. int check4[__LONG_MAX__ >= 2147483647 ? 1 : -1];
  883. int check5[__LONG_LONG_MAX__ >= 9223372036854775807 ? 1 : -1];
  884. #if __cplusplus < 201103L
  885. // expected-error@-2 {{extension}}
  886. #endif
  887. }
  888. namespace cstdint {
  889. int check1[__PTRDIFF_WIDTH__ >= 16 ? 1 : -1];
  890. int check2[__SIG_ATOMIC_WIDTH__ >= 8 ? 1 : -1];
  891. int check3[__SIZE_WIDTH__ >= 16 ? 1 : -1];
  892. int check4[__WCHAR_WIDTH__ >= 8 ? 1 : -1];
  893. int check5[__WINT_WIDTH__ >= 16 ? 1 : -1];
  894. }
  895. }
  896. namespace dr484 { // dr484: yes
  897. struct A {
  898. A();
  899. void f();
  900. };
  901. typedef const A CA;
  902. void CA::f() {
  903. this->~CA();
  904. this->CA::~A();
  905. this->CA::A::~A();
  906. }
  907. CA::A() {}
  908. struct B : CA {
  909. B() : CA() {}
  910. void f() { return CA::f(); }
  911. };
  912. struct C;
  913. typedef C CT; // expected-note {{here}}
  914. struct CT {}; // expected-error {{conflicts with typedef}}
  915. namespace N {
  916. struct D;
  917. typedef D DT; // expected-note {{here}}
  918. }
  919. struct N::DT {}; // expected-error {{conflicts with typedef}}
  920. typedef struct {
  921. S(); // expected-error {{requires a type}}
  922. } S;
  923. }
  924. namespace dr485 { // dr485: yes
  925. namespace N {
  926. struct S {};
  927. int operator+(S, S);
  928. template<typename T> int f(S);
  929. }
  930. template<typename T> int f();
  931. N::S s;
  932. int a = operator+(s, s);
  933. int b = f<int>(s);
  934. }
  935. namespace dr486 { // dr486: yes
  936. template<typename T> T f(T *); // expected-note 2{{substitution failure}}
  937. int &f(...);
  938. void g();
  939. int n[10];
  940. void h() {
  941. int &a = f(&g);
  942. int &b = f(&n);
  943. f<void()>(&g); // expected-error {{no match}}
  944. f<int[10]>(&n); // expected-error {{no match}}
  945. }
  946. }
  947. namespace dr487 { // dr487: yes
  948. enum E { e };
  949. int operator+(int, E);
  950. int i[4 + e]; // expected-error 2{{variable length array}}
  951. }
  952. namespace dr488 { // dr488: yes c++11
  953. template <typename T> void f(T);
  954. void f(int);
  955. void g() {
  956. // FIXME: It seems CWG thought this should be a SFINAE failure prior to
  957. // allowing local types as template arguments. In C++98, we should either
  958. // allow local types as template arguments or treat this as a SFINAE
  959. // failure.
  960. enum E { e };
  961. f(e);
  962. #if __cplusplus < 201103L
  963. // expected-error@-2 {{local type}}
  964. #endif
  965. }
  966. }
  967. // dr489: na
  968. namespace dr490 { // dr490: yes
  969. template<typename T> struct X {};
  970. struct A {
  971. typedef int T;
  972. struct K {}; // expected-note {{declared}}
  973. int f(T);
  974. int g(T);
  975. int h(X<T>);
  976. int X<T>::*i(); // expected-note {{previous}}
  977. int K::*j();
  978. template<typename T> T k();
  979. operator X<T>();
  980. };
  981. struct B {
  982. typedef char T;
  983. typedef int U;
  984. friend int A::f(T);
  985. friend int A::g(U);
  986. friend int A::h(X<T>);
  987. // FIXME: Per this DR, these two are valid! That is another defect
  988. // (no number yet...) which will eventually supersede this one.
  989. friend int X<T>::*A::i(); // expected-error {{return type}}
  990. friend int K::*A::j(); // expected-error {{undeclared identifier 'K'; did you mean 'A::K'?}}
  991. // ok, lookup finds B::T, not A::T, so return type matches
  992. friend char A::k<T>();
  993. friend int A::k<U>();
  994. // A conversion-type-id in a conversion-function-id is always looked up in
  995. // the class of the conversion function first.
  996. friend A::operator X<T>();
  997. };
  998. }
  999. namespace dr491 { // dr491: dup 413
  1000. struct A {} a, b[3] = { a, {} };
  1001. A c[2] = { a, {}, b[1] }; // expected-error {{excess elements}}
  1002. }
  1003. // dr492 FIXME write a codegen test
  1004. namespace dr493 { // dr493: dup 976
  1005. struct X {
  1006. template <class T> operator const T &() const;
  1007. };
  1008. void f() {
  1009. if (X()) {
  1010. }
  1011. }
  1012. }
  1013. namespace dr494 { // dr494: dup 372
  1014. class A {
  1015. class B {};
  1016. friend class C;
  1017. };
  1018. class C : A::B {
  1019. A::B x;
  1020. class D : A::B {
  1021. A::B y;
  1022. };
  1023. };
  1024. }
  1025. namespace dr495 { // dr495: 3.5
  1026. template<typename T>
  1027. struct S {
  1028. operator int() { return T::error; }
  1029. template<typename U> operator U();
  1030. };
  1031. S<int> s;
  1032. long n = s;
  1033. template<typename T>
  1034. struct S2 {
  1035. template<typename U> operator U();
  1036. operator int() { return T::error; }
  1037. };
  1038. S2<int> s2;
  1039. long n2 = s2;
  1040. }
  1041. namespace dr496 { // dr496: no
  1042. struct A { int n; };
  1043. struct B { volatile int n; };
  1044. int check1[ __is_trivially_copyable(const int) ? 1 : -1];
  1045. int check2[!__is_trivially_copyable(volatile int) ? 1 : -1];
  1046. int check3[ __is_trivially_constructible(A, const A&) ? 1 : -1];
  1047. // FIXME: This is wrong.
  1048. int check4[ __is_trivially_constructible(B, const B&) ? 1 : -1];
  1049. int check5[ __is_trivially_assignable(A, const A&) ? 1 : -1];
  1050. // FIXME: This is wrong.
  1051. int check6[ __is_trivially_assignable(B, const B&) ? 1 : -1];
  1052. }
  1053. namespace dr497 { // dr497: yes
  1054. void before() {
  1055. struct S {
  1056. mutable int i;
  1057. };
  1058. const S cs; // expected-error {{default initialization}}
  1059. int S::*pm = &S::i;
  1060. cs.*pm = 88; // expected-error {{not assignable}}
  1061. }
  1062. void after() {
  1063. struct S {
  1064. S() : i(0) {}
  1065. mutable int i;
  1066. };
  1067. const S cs;
  1068. int S::*pm = &S::i;
  1069. cs.*pm = 88; // expected-error {{not assignable}}
  1070. }
  1071. }
  1072. namespace dr499 { // dr499: yes
  1073. extern char str[];
  1074. void f() { throw str; }
  1075. }