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 namespace dr2229 { // dr2229: 7
7 struct AnonBitfieldQualifiers {
8 const unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
9 volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
10 const volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
11
12 unsigned : 1;
13 const unsigned i1 : 1;
14 volatile unsigned i2 : 1;
15 const volatile unsigned i3 : 1;
16 };
17 }
18
19 #if __cplusplus >= 201103L
20 namespace dr2211 { // dr2211: 8
f()21 void f() {
22 int a;
23 auto f = [a](int a) { (void)a; }; // expected-error {{a lambda parameter cannot shadow an explicitly captured entity}}
24 // expected-note@-1{{variable 'a' is explicitly captured here}}
25 auto g = [=](int a) { (void)a; };
26 }
27 }
28 #endif
29
30 namespace dr2292 { // dr2292: 9
31 #if __cplusplus >= 201103L
32 template<typename T> using id = T;
test(int * p)33 void test(int *p) {
34 p->template id<int>::~id<int>();
35 }
36 #endif
37 }
38
39 namespace dr2233 { // dr2233: 11
40 #if __cplusplus >= 201103L
41 template <typename... T>
f(int i=0,T...args)42 void f(int i = 0, T... args) {}
43
44 template <typename... T>
g(int i=0,T...args,T...args2)45 void g(int i = 0, T... args, T... args2) {}
46
47 template <typename... T>
h(int i=0,T...args,int j=1)48 void h(int i = 0, T... args, int j = 1) {}
49
50 template <typename... T, typename... U>
i(int i=0,T...args,int j=1,U...args2)51 void i(int i = 0, T... args, int j = 1, U... args2) {}
52
53 template <class... Ts>
j(int i=0,Ts...ts)54 void j(int i = 0, Ts... ts) {}
55
56 template <>
j(int i,int j)57 void j<int>(int i, int j) {}
58
59 template
60 void j(int, int, int);
61
62 extern template
63 void j(int, int, int, int);
64
65 // PR23029
66 // Ensure instantiating the templates works.
use()67 void use() {
68 f();
69 f(0, 1);
70 f<int>(1, 2);
71 g<int>(1, 2, 3);
72 h(0, 1);
73 i();
74 i(3);
75 i<int>(3, 2);
76 i<int>(3, 2, 1);
77 i<int, int>(1, 2, 3, 4, 5);
78 j();
79 j(1);
80 j(1, 2);
81 j<int>(1, 2);
82 }
83
84 namespace MultilevelSpecialization {
85 template<typename ...T> struct A {
86 template <T... V> void f(int i = 0, int (&... arr)[V]);
87 };
88 template<> template<>
f(int i,int (& arr1a)[1],int (& arr2a)[1])89 void A<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
90
91 // FIXME: I believe this example is valid, at least up to the first explicit
92 // specialization, but Clang can't cope with explicit specializations that
93 // expand packs into a sequence of parameters. If we ever start accepting
94 // that, we'll need to decide whether it's OK for arr1a to be missing its
95 // default argument -- how far back do we look when determining whether a
96 // parameter was expanded from a pack?
97 // -- zygoloid 2020-06-02
98 template<typename ...T> struct B {
99 template <T... V> void f(int i = 0, int (&... arr)[V]);
100 };
101 template<> template<int a, int b>
f(int i,int (& arr1)[a],int (& arr2)[b])102 void B<int, int>::f(int i, int (&arr1)[a], int (&arr2)[b]) {} // expected-error {{does not match}}
103 template<> template<>
f(int i,int (& arr1a)[1],int (& arr2a)[1])104 void B<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
105 }
106
107 namespace CheckAfterMerging1 {
f()108 template <typename... T> void f() {
109 void g(int, int = 0);
110 void g(int = 0, T...);
111 g();
112 }
h()113 void h() { f<int>(); }
114 }
115
116 namespace CheckAfterMerging2 {
f()117 template <typename... T> void f() {
118 void g(int = 0, T...);
119 void g(int, int = 0);
120 g();
121 }
h()122 void h() { f<int>(); }
123 }
124 #endif
125 } // namespace dr2233
126