Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr17xx.cpp
blob219119d1a4cd087368e4dad08e395257e50e991d
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++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
9 namespace dr1710 { // dr1710: no
10 // FIXME: all of the following is well-formed
11 template <typename T> struct D1 : T::template B<int>::template C<int> {};
12 template <typename T> struct D2 : T::B<int>::template C<int> {};
13 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
14 template <typename T> struct D3 : T::template B<int>::C<int> {};
15 // expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent template name}}
16 template <typename T> struct D4 : T::B<int>::C<int> {};
17 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
18 // expected-error@-2 {{use 'template' keyword to treat 'C' as a dependent template name}}
19 } // namespace dr1710
21 namespace dr1715 { // dr1715: 3.9
22 #if __cplusplus >= 201103L
23 struct B {
24 template<class T> B(T, typename T::Q);
27 class S {
28 using Q = int;
29 template<class T> friend B::B(T, typename T::Q);
32 struct D : B {
33 using B::B;
35 struct E : B { // expected-note 2{{candidate}}
36 template<class T> E(T t, typename T::Q q) : B(t, q) {} // expected-note {{'Q' is a private member}}
39 B b(S(), 1);
40 D d(S(), 2);
41 E e(S(), 3); // expected-error {{no match}}
42 #endif
45 namespace dr1722 { // dr1722: 9
46 #if __cplusplus >= 201103L
47 void f() {
48 const auto lambda = [](int x) { return x + 1; };
49 // Without the DR applied, this static_assert would fail.
50 static_assert(
51 noexcept((int (*)(int))(lambda)),
52 "Lambda-to-function-pointer conversion is expected to be noexcept");
54 #endif
55 } // namespace dr1722
57 namespace dr1734 { // dr1734: no
58 #if __cplusplus >= 201103L
59 struct A {
60 A(const A&) = delete;
62 // FIXME: 'A' should not be trivially copyable because the class lacks at least
63 // one non-deleted copy constructor, move constructor, copy assignment
64 // operator, or move assignment operator.
65 static_assert(__is_trivially_copyable(A), "");
66 #endif
69 namespace dr1736 { // dr1736: 3.9
70 #if __cplusplus >= 201103L
71 struct S {
72 template <class T> S(T t) {
73 struct L : S {
74 using S::S;
76 typename T::type value; // expected-error {{no member}}
77 L l(value); // expected-note {{instantiation of}}
80 struct Q { typedef int type; } q;
81 S s(q); // expected-note {{instantiation of}}
82 #endif
85 namespace dr1753 { // dr1753: 11
86 typedef int T;
87 struct A { typedef int T; };
88 namespace B { typedef int T; }
90 void f(T n) {
91 n.~T();
92 n.T::~T();
94 n.dr1753::~T(); // expected-error {{'dr1753' does not refer to a type name in pseudo-destructor}}
95 n.dr1753::T::~T();
97 n.A::~T(); // expected-error {{the type of object expression ('T' (aka 'int')) does not match the type being destroyed ('A') in pseudo-destructor expression}}
98 n.A::T::~T();
100 n.B::~T(); // expected-error {{'B' does not refer to a type name in pseudo-destructor expression}}
101 n.B::T::~T();
103 #if __cplusplus >= 201103L
104 n.decltype(n)::~T(); // expected-error {{not a class, namespace, or enumeration}}
105 n.T::~decltype(n)(); // expected-error {{expected a class name after '~'}}
106 n.~decltype(n)(); // OK
107 #endif
111 namespace dr1756 { // dr1756: 3.7
112 #if __cplusplus >= 201103L
113 // Direct-list-initialization of a non-class object
115 int a{0};
117 struct X { operator int(); } x;
118 int b{x};
119 #endif
122 namespace dr1758 { // dr1758: 3.7
123 #if __cplusplus >= 201103L
124 // Explicit conversion in copy/move list initialization
126 struct X { X(); };
127 struct Y { explicit operator X(); } y;
128 X x{y};
130 struct A {
131 A() {}
132 A(const A &) {}
134 struct B {
135 operator A() { return A(); }
136 } b;
137 A a{b};
138 #endif
141 namespace dr1762 { // dr1762: 14
142 #if __cplusplus >= 201103L
143 float operator ""_E(const char *);
144 // expected-error@+2 {{invalid suffix on literal; C++11 requires a space between literal and identifier}}
145 // expected-warning@+1 {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
146 float operator ""E(const char *);
147 #endif
150 namespace dr1778 { // dr1778: 9
151 // Superseded by P1286R2.
152 #if __cplusplus >= 201103L
153 struct A { A() noexcept(true) = default; };
154 struct B { B() noexcept(false) = default; };
155 static_assert(noexcept(A()), "");
156 static_assert(!noexcept(B()), "");
158 struct C { A a; C() noexcept(false) = default; };
159 struct D { B b; D() noexcept(true) = default; };
160 static_assert(!noexcept(C()), "");
161 static_assert(noexcept(D()), "");
162 #endif
165 namespace dr1794 { // dr1794: yes
166 // NB: dup 1710
167 #if __cplusplus >= 201103L
168 template <template <typename> class Template> struct Internal {
169 template <typename Arg> using Bind = Template<Arg>;
172 template <template <typename> class Template, typename Arg>
173 using Instantiate = Template<Arg>;
175 template <template <typename> class Template, typename Argument>
176 using Bind = Instantiate<Internal<Template>::template Bind, Argument>;
177 #endif
178 } // namespace dr1794