Clang Project

clang_source_code/test/CXX/drs/dr18xx.cpp
1// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5
6#if __cplusplus < 201103L
7// expected-error@+1 {{variadic macro}}
8#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
9#endif
10
11namespace dr1813 { // dr1813: 7
12  struct B { int i; };
13  struct C : B {};
14  struct D : C {};
15  struct E : D { char : 4; };
16
17  static_assert(__is_standard_layout(B), "");
18  static_assert(__is_standard_layout(C), "");
19  static_assert(__is_standard_layout(D), "");
20  static_assert(!__is_standard_layout(E), "");
21
22  struct Q {};
23  struct S : Q {};
24  struct T : Q {};
25  struct U : S, T {};
26
27  static_assert(__is_standard_layout(Q), "");
28  static_assert(__is_standard_layout(S), "");
29  static_assert(__is_standard_layout(T), "");
30  static_assert(!__is_standard_layout(U), "");
31}
32
33namespace dr1815 { // dr1815: no
34#if __cplusplus >= 201402L
35  // FIXME: needs codegen test
36  struct A { int &&r = 0; }; // expected-note {{default member init}}
37  A a = {}; // FIXME expected-warning {{not supported}}
38
39  struct B { int &&r = 0; }; // expected-error {{binds to a temporary}} expected-note {{default member init}}
40  B b; // expected-note {{here}}
41#endif
42}
43
44namespace dr1881 { // dr1881: 7
45  struct A { int a : 4; };
46  struct B : A { int b : 3; };
47  static_assert(__is_standard_layout(A), "");
48  static_assert(!__is_standard_layout(B), "");
49
50  struct C { int : 0; };
51  struct D : C { int : 0; };
52  static_assert(__is_standard_layout(C), "");
53  static_assert(!__is_standard_layout(D), "");
54}
55
56void dr1891() { // dr1891: 4
57#if __cplusplus >= 201103L
58  int n;
59  auto a = []{}; // expected-note 2{{candidate}} expected-note 2{{here}}
60  auto b = [=]{ return n; }; // expected-note 2{{candidate}} expected-note 2{{here}}
61  typedef decltype(a) A;
62  typedef decltype(b) B;
63
64  static_assert(!__has_trivial_constructor(A), "");
65  static_assert(!__has_trivial_constructor(B), "");
66
67  A x; // expected-error {{no matching constructor}}
68  B y; // expected-error {{no matching constructor}}
69
70  a = a; // expected-error {{copy assignment operator is implicitly deleted}}
71  a = static_cast<A&&>(a); // expected-error {{copy assignment operator is implicitly deleted}}
72  b = b; // expected-error {{copy assignment operator is implicitly deleted}}
73  b = static_cast<B&&>(b); // expected-error {{copy assignment operator is implicitly deleted}}
74#endif
75}
76