default-expr-arguments.cpp revision 21e1c4ea0a96bcecfe5976304d84779949058648
1// RUN: clang-cc -fsyntax-only -verify %s
2
3struct S { };
4
5template<typename T> void f1(T a, T b = 10) { } // expected-error{{cannot initialize 'b' with an rvalue of type 'int'}}
6
7template<typename T> void f2(T a, T b = T()) { }
8
9template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('struct S' and 'struct S')}}
10
11void g() {
12  f1(10);
13  f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<struct S>' required here}}
14
15  f2(10);
16  f2(S());
17
18  f3(10);
19  f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<struct S>' required here}}
20}
21
22template<typename T> struct F {
23  F(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}}
24  void f(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}}
25};
26
27struct FD : F<int> { };
28
29void g2() {
30  F<int> f;
31  FD fd;
32}
33
34void g3(F<int> f, F<struct S> s) {
35  f.f();
36  s.f(); // expected-note{{in instantiation of default function argument expression for 'f<struct S>' required here}}
37
38  F<int> f2;
39  F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<struct S>' required here}}
40}
41
42template<typename T> struct G {
43  G(T) {}
44};
45
46void s(G<int> flags = 10) { }
47
48
49
50