]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaTemplate/default-expr-arguments.cpp
Update clang to r86025.
[FreeBSD/FreeBSD.git] / test / SemaTemplate / default-expr-arguments.cpp
1 // RUN: clang-cc -fsyntax-only -verify %s
2
3 template<typename T>
4 class C { C(int a0 = 0); };
5
6 template<>
7 C<char>::C(int a0);
8
9 struct S { };
10
11 template<typename T> void f1(T a, T b = 10) { } // expected-error{{cannot initialize 'b' with an rvalue of type 'int'}}
12
13 template<typename T> void f2(T a, T b = T()) { }
14
15 template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('struct S' and 'struct S')}}
16
17 void g() {
18   f1(10);
19   f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<struct S>' required here}}
20   
21   f2(10);
22   f2(S());
23   
24   f3(10);
25   f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<struct S>' required here}}
26 }
27
28 template<typename T> struct F {
29   F(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}}
30   void f(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}}
31 };
32
33 struct FD : F<int> { };
34
35 void g2() {
36   F<int> f;
37   FD fd;
38 }
39
40 void g3(F<int> f, F<struct S> s) {
41   f.f();
42   s.f(); // expected-note{{in instantiation of default function argument expression for 'f<struct S>' required here}}
43   
44   F<int> f2;
45   F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<struct S>' required here}}
46 }
47
48 template<typename T> struct G {
49   G(T) {}
50 };
51
52 void s(G<int> flags = 10) { }
53
54 // Test default arguments
55 template<typename T>
56 struct X0 {
57   void f(T = T()); // expected-error{{no matching}}
58 };
59
60 template<typename U>
61 void X0<U>::f(U) { }
62
63 void test_x0(X0<int> xi) {
64   xi.f();
65   xi.f(17);
66 }
67
68 struct NotDefaultConstructible { // expected-note{{candidate}}
69   NotDefaultConstructible(int); // expected-note{{candidate}}
70 };
71
72 void test_x0_not_default_constructible(X0<NotDefaultConstructible> xn) {
73   xn.f(NotDefaultConstructible(17));
74   xn.f(42);
75   xn.f(); // expected-note{{in instantiation of default function argument}}
76 }
77
78 template<typename T>
79 struct X1 {
80   typedef T value_type;
81   X1(const value_type& value = value_type());
82 };
83
84 void test_X1() {
85   X1<int> x1;
86 }
87
88 // PR5283
89 namespace PR5283 {
90 template<typename T> struct A {
91   A(T = 1); // expected-error 3 {{incompatible type initializing 'int', expected 'int *'}}
92 };
93
94 struct B : A<int*> { 
95   B();
96 };
97 B::B() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
98
99 struct C : virtual A<int*> {
100   C();
101 };
102 C::C() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
103
104 struct D {
105   D();
106   
107   A<int*> a;
108 };
109 D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
110 }