1 // RUN: clang-cc -fsyntax-only -verify %s
3 void f(int i, int j, int k = 3);
4 void f(int i, int j, int k);
5 void f(int i, int j = 2, int k);
6 void f(int i, int j, int k);
7 void f(int i = 1, int j, int k);
8 void f(int i, int j, int k);
19 int f1(int i, int i, int j) { // expected-error {{redefinition of parameter 'i'}}
25 void g(int x, int y = x); // expected-error {{default argument references parameter 'x'}}
27 void g2(int x, int y, int z = x + y); // expected-error {{default argument references parameter 'x'}} expected-error {{default argument references parameter 'y'}}
30 void f(X* x = this); // expected-error{{invalid use of 'this' outside of a nonstatic member function}}
33 int f(X* x = this); // expected-error{{default argument references 'this'}}
37 // C++ [dcl.fct.default]p6
40 void f(int i = 3); // expected-note{{previous definition is here}}
41 void g(int i, int j = x);
45 void C::f(int i = 3) // expected-error{{redefinition of default argument}}
48 void C::g(int i = 88, int j) {}
54 // C++ [dcl.fct.default]p9
57 int mem1(int i = a); // expected-error{{invalid use of nonstatic data member 'a'}}
58 int mem2(int i = b); // OK; use Y::b
63 int mem5(int i = b, // OK; use Y::b
64 int j = c, // OK; use Y::Nested::c
65 int k = j, // expected-error{{default argument references parameter 'j'}}
66 int l = a, // expected-error{{invalid use of nonstatic data member 'a'}}
67 Nested* self = this, // expected-error{{invalid use of 'this' outside of a nonstatic member function}}
68 int m); // expected-error{{missing default argument on parameter 'm'}}
75 int Y::mem3(int i = b) { return i; } // OK; use X::b
77 int Y::mem4(int i = a) // expected-error{{invalid use of nonstatic data member 'a'}}
81 // Try to verify that default arguments interact properly with copy
85 Z(Z&, int i = 17); // expected-note 2 {{candidate function}}
88 Z z2; // expected-error{{no matching constructor for initialization}}
92 void test_Z(const Z& z) {
93 Z z2(z); // expected-error{{no matching constructor for initialization of 'z2'}}
97 void test_Z(const Z& z) {
98 Z z2(z); // expected-error{{no matching constructor for initialization of 'z2'}}
102 static ZZ g(int = 17);
104 void f(ZZ z = g()); // expected-error{{no matching constructor for initialization}}
106 ZZ(ZZ&, int = 17); // expected-note{{candidate function}}
109 // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#325
111 static void g(int = f()); // expected-error{{use of default argument to function 'f' that is declared later in class 'C2'}}
112 static int f(int = 10); // expected-note{{default argument declared here}}
115 // Make sure we actually parse the default argument for an inline definition
117 void A(int length = -1 ) { }