Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr22xx.cpp
blobcd849443b1119bac90c7e62a736584ddb923e55e
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
6 #if __cplusplus >= 201103L
7 namespace dr2211 { // dr2211: 8
8 void f() {
9 int a;
10 auto f = [a](int a) { (void)a; }; // expected-error {{a lambda parameter cannot shadow an explicitly captured entity}}
11 // expected-note@-1{{variable 'a' is explicitly captured here}}
12 auto g = [=](int a) { (void)a; };
15 #endif
17 namespace dr2213 { // dr2213: yes
18 template <typename T, typename U>
19 struct A;
21 template <typename U>
22 struct A<int, U>;
23 } // namespace dr2213
25 namespace dr2229 { // dr2229: 7
26 struct AnonBitfieldQualifiers {
27 const unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
28 volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
29 const volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
31 unsigned : 1;
32 const unsigned i1 : 1;
33 volatile unsigned i2 : 1;
34 const volatile unsigned i3 : 1;
38 namespace dr2233 { // dr2233: 11
39 #if __cplusplus >= 201103L
40 template <typename... T>
41 void f(int i = 0, T... args) {}
43 template <typename... T>
44 void g(int i = 0, T... args, T... args2) {}
46 template <typename... T>
47 void h(int i = 0, T... args, int j = 1) {}
49 template <typename... T, typename... U>
50 void i(int i = 0, T... args, int j = 1, U... args2) {}
52 template <class... Ts>
53 void j(int i = 0, Ts... ts) {}
55 template <>
56 void j<int>(int i, int j) {}
58 template
59 void j(int, int, int);
61 extern template
62 void j(int, int, int, int);
64 // PR23029
65 // Ensure instantiating the templates works.
66 void use() {
67 f();
68 f(0, 1);
69 f<int>(1, 2);
70 g<int>(1, 2, 3);
71 h(0, 1);
72 i();
73 i(3);
74 i<int>(3, 2);
75 i<int>(3, 2, 1);
76 i<int, int>(1, 2, 3, 4, 5);
77 j();
78 j(1);
79 j(1, 2);
80 j<int>(1, 2);
83 namespace MultilevelSpecialization {
84 template<typename ...T> struct A {
85 template <T... V> void f(int i = 0, int (&... arr)[V]);
87 template<> template<>
88 void A<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
90 // FIXME: I believe this example is valid, at least up to the first explicit
91 // specialization, but Clang can't cope with explicit specializations that
92 // expand packs into a sequence of parameters. If we ever start accepting
93 // that, we'll need to decide whether it's OK for arr1a to be missing its
94 // default argument -- how far back do we look when determining whether a
95 // parameter was expanded from a pack?
96 // -- zygoloid 2020-06-02
97 template<typename ...T> struct B {
98 template <T... V> void f(int i = 0, int (&... arr)[V]);
100 template<> template<int a, int b>
101 void B<int, int>::f(int i, int (&arr1)[a], int (&arr2)[b]) {} // expected-error {{does not match}}
102 template<> template<>
103 void B<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
106 namespace CheckAfterMerging1 {
107 template <typename... T> void f() {
108 void g(int, int = 0);
109 void g(int = 0, T...);
110 g();
112 void h() { f<int>(); }
115 namespace CheckAfterMerging2 {
116 template <typename... T> void f() {
117 void g(int = 0, T...);
118 void g(int, int = 0);
119 g();
121 void h() { f<int>(); }
123 #endif
124 } // namespace dr2233
126 namespace dr2267 { // dr2267: no
127 #if __cplusplus >= 201103L
128 struct A {} a;
129 struct B { explicit B(const A&); }; // #dr2267-struct-B
131 struct D { D(); };
132 struct C { explicit operator D(); } c;
134 B b1(a);
135 const B &b2{a}; // FIXME ill-formed
136 const B &b3(a);
137 // expected-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
138 // expected-note@#dr2267-struct-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const B &' for 1st argument}}
139 // expected-note@#dr2267-struct-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st argument}}
140 // expected-note@#dr2267-struct-B {{explicit constructor is not a candidate}}
142 D d1(c);
143 const D &d2{c}; // FIXME ill-formed
144 const D &d3(c); // FIXME ill-formed
145 #endif
148 namespace dr2292 { // dr2292: 9
149 #if __cplusplus >= 201103L
150 template<typename T> using id = T;
151 void test(int *p) {
152 p->template id<int>::~id<int>();
154 #endif