1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx11-14 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 %std_cxx17- %s
4 void f(int i
, int j
, int k
= 3);
5 void f(int i
, int j
, int k
);
6 void f(int i
, int j
= 2, int k
);
7 void f(int i
, int j
, int k
);
8 void f(int i
= 1, int j
, int k
);
9 void f(int i
, int j
, int k
);
20 int f1(int i
, // expected-note {{previous declaration is here}}
21 int i
, int j
) { // expected-error {{redefinition of parameter 'i'}}
27 void g(int x
, int y
= x
); // expected-error {{default argument references parameter 'x'}}
29 void g2(int x
, int y
, int z
= x
+ y
); // expected-error {{default argument references parameter 'x'}} expected-error {{default argument references parameter 'y'}}
32 void f(X
* x
= this); // expected-error{{invalid use of 'this' outside of a non-static member function}}
35 int f(X
* x
= this); // expected-error{{default argument references 'this'}}
39 // C++ [dcl.fct.default]p6
42 void f(int i
= 3); // expected-note{{previous definition is here}}
43 void g(int i
, int j
= x
);
47 void C::f(int i
= 3) // expected-error{{redefinition of default argument}}
50 void C::g(int i
= 88, int j
) {}
56 // C++ [dcl.fct.default]p9
59 int mem1(int i
= a
); // expected-error{{invalid use of non-static data member 'a'}}
60 int mem2(int i
= b
); // OK; use Y::b
65 int mem5(int i
= b
, // OK; use Y::b
66 int j
= c
, // OK; use Y::Nested::c
67 int k
= j
, // expected-error{{default argument references parameter 'j'}}
68 int l
= a
, // expected-error{{invalid use of non-static data member 'a'}}
69 Nested
* self
= this, // expected-error{{invalid use of 'this' outside of a non-static member function}}
70 int m
); // expected-error{{missing default argument on parameter 'm'}}
75 int mem7(Nested n
= Nested());
80 int Y::mem3(int i
= b
) { return i
; } // OK; use X::b
82 int Y::mem4(int i
= a
) // expected-error{{invalid use of non-static data member 'a'}}
86 // Try to verify that default arguments interact properly with copy
90 Z(Z
&, int i
= 17); // expected-note 3 {{candidate constructor}}
93 Z z2
; // expected-error{{no matching constructor for initialization}}
97 void test_Z(const Z
& z
) {
98 Z
z2(z
); // expected-error{{no matching constructor for initialization of 'Z'}}
102 void test_Z(const Z
& z
) {
103 Z
z2(z
); // expected-error{{no matching constructor for initialization of 'Z'}}
107 static ZZ
g(int = 17);
109 void f(ZZ z
= g()); // precxx17-error{{no matching constructor for initialization}} \
110 // precxx17-note{{passing argument to parameter 'z' here}}
112 ZZ(ZZ
&, int = 17); // precxx17-note{{candidate constructor}}
115 // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#325
117 static void g(int = f()); // expected-error{{use of default argument to function 'f' that is declared later in class 'C2'}}
118 static int f(int = 10); // expected-note{{default argument declared here}}
121 template <typename T
> class C3
;
122 template <> class C3
<int> {
123 static void g(int = f()); // expected-error {{use of default argument to function 'f' that is declared later in class 'C3<int>'}}
124 static int f(int = 10); // expected-note {{default argument declared here}}
127 // Make sure we actually parse the default argument for an inline definition
129 void A(int length
= -1 ) { }
133 template <int I
= (1 * I
)> struct S
{}; // expected-error-re {{use of undeclared identifier 'I'{{$}}}}
136 template <int I1
= I2
, int I2
= 1> struct T
{}; // expected-error-re {{use of undeclared identifier 'I2'{{$}}}}
140 PR28105 (int = 0, int = 0,
141 PR28105
// expected-error{{recursive evaluation of default argument}}
143 0); // expected-note {{default argument used here}}