1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
void f(int i, int j, int k = 3);
void f(int i, int j, int k);
void f(int i, int j = 2, int k);
void f(int i, int j, int k);
void f(int i = 1, int j, int k);
void f(int i, int j, int k);
void i()
{
f();
f(0);
f(0, 1);
f(0, 1, 2);
}
int f1(int i, // expected-note {{previous declaration is here}}
int i, int j) { // expected-error {{redefinition of parameter 'i'}}
i = 17;
return j;
}
int x;
void g(int x, int y = x); // expected-error {{default argument references parameter 'x'}}
void g2(int x, int y, int z = x + y); // expected-error {{default argument references parameter 'x'}} expected-error {{default argument references parameter 'y'}}
class X {
void f(X* x = this); // expected-error{{invalid use of 'this' outside of a non-static member function}}
void g() {
int f(X* x = this); // expected-error{{default argument references 'this'}}
}
};
// C++ [dcl.fct.default]p6
class C {
static int x;
void f(int i = 3); // expected-note{{previous definition is here}}
void g(int i, int j = x);
void h();
};
void C::f(int i = 3) // expected-error{{redefinition of default argument}}
{ }
void C::g(int i = 88, int j) {}
void C::h() {
g(); // okay
}
// C++ [dcl.fct.default]p9
struct Y {
int a;
int mem1(int i = a); // expected-error{{invalid use of non-static data member 'a'}}
int mem2(int i = b); // OK; use Y::b
int mem3(int i);
int mem4(int i);
struct Nested {
int mem5(int i = b, // OK; use Y::b
int j = c, // OK; use Y::Nested::c
int k = j, // expected-error{{default argument references parameter 'j'}}
int l = a, // expected-error{{invalid use of non-static data member 'a'}}
Nested* self = this, // expected-error{{invalid use of 'this' outside of a non-static member function}}
int m); // expected-error{{missing default argument on parameter 'm'}}
static int c;
Nested(int i = 42);
};
int mem7(Nested n = Nested());
static int b;
};
int Y::mem3(int i = b) { return i; } // OK; use X::b
int Y::mem4(int i = a) // expected-error{{invalid use of non-static data member 'a'}}
{ return i; }
// Try to verify that default arguments interact properly with copy
// constructors.
class Z {
public:
Z(Z&, int i = 17); // expected-note 3 {{candidate constructor}}
void f(Z& z) {
Z z2; // expected-error{{no matching constructor for initialization}}
Z z3(z);
}
void test_Z(const Z& z) {
Z z2(z); // expected-error{{no matching constructor for initialization of 'Z'}}
}
};
void test_Z(const Z& z) {
Z z2(z); // expected-error{{no matching constructor for initialization of 'Z'}}
}
struct ZZ {
static ZZ g(int = 17);
void f(ZZ z = g()); // expected-error{{no matching constructor for initialization}} \
// expected-note{{passing argument to parameter 'z' here}}
ZZ(ZZ&, int = 17); // expected-note{{candidate constructor}}
};
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#325
class C2 {
static void g(int = f()); // expected-error{{use of default argument to function 'f' that is declared later in class 'C2'}}
static int f(int = 10); // expected-note{{default argument declared here}}
};
// Make sure we actually parse the default argument for an inline definition
class XX {
void A(int length = -1 ) { }
void B() { A(); }
};
template <int I = (1 * I)> struct S {}; // expected-error-re {{use of undeclared identifier 'I'{{$}}}}
S<1> s;
template <int I1 = I2, int I2 = 1> struct T {}; // expected-error-re {{use of undeclared identifier 'I2'{{$}}}}
T<0, 1> t;
struct PR28105 {
PR28105 (int = 0, int = 0, PR28105 = 0); // expected-error{{recursive evaluation of default argument}}
};
|