| 1 |
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -triple i386-windows |
| 3 |
|
| 4 |
void defargs() { |
| 5 |
auto l1 = [](int i, int j = 17, int k = 18) { return i + j + k; }; |
| 6 |
int i1 = l1(1); |
| 7 |
int i2 = l1(1, 2); |
| 8 |
int i3 = l1(1, 2, 3); |
| 9 |
} |
| 10 |
|
| 11 |
|
| 12 |
void defargs_errors() { |
| 13 |
auto l1 = [](int i, |
| 14 |
int j = 17, |
| 15 |
int k) { }; // expected-error{{missing default argument on parameter 'k'}} |
| 16 |
|
| 17 |
auto l2 = [](int i, int j = i) {}; // expected-error{{default argument references parameter 'i'}} |
| 18 |
|
| 19 |
int foo; |
| 20 |
auto l3 = [](int i = foo) {}; // expected-error{{default argument references local variable 'foo' of enclosing function}} |
| 21 |
} |
| 22 |
|
| 23 |
struct NonPOD { |
| 24 |
NonPOD(); |
| 25 |
NonPOD(const NonPOD&); |
| 26 |
~NonPOD(); |
| 27 |
}; |
| 28 |
|
| 29 |
struct NoDefaultCtor { |
| 30 |
NoDefaultCtor(const NoDefaultCtor&); // expected-note{{candidate constructor}} \ |
| 31 |
// expected-note{{candidate constructor not viable: requires 1 argument, but 0 were provided}} |
| 32 |
~NoDefaultCtor(); |
| 33 |
}; |
| 34 |
|
| 35 |
template<typename T> |
| 36 |
void defargs_in_template_unused(T t) { |
| 37 |
auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}} \ |
| 38 |
// expected-note {{in instantiation of default function argument expression for 'operator()<NoDefaultCtor>' required here}} |
| 39 |
l1(t); |
| 40 |
} |
| 41 |
|
| 42 |
template void defargs_in_template_unused(NonPOD); |
| 43 |
template void defargs_in_template_unused(NoDefaultCtor); // expected-note{{in instantiation of function template specialization 'defargs_in_template_unused<NoDefaultCtor>' requested here}} |
| 44 |
|
| 45 |
template<typename T> |
| 46 |
void defargs_in_template_used() { |
| 47 |
auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}} \ |
| 48 |
// expected-note {{in instantiation of default function argument expression for 'operator()<NoDefaultCtor>' required here}} |
| 49 |
l1(); |
| 50 |
} |
| 51 |
|
| 52 |
template void defargs_in_template_used<NonPOD>(); |
| 53 |
template void defargs_in_template_used<NoDefaultCtor>(); // expected-note{{in instantiation of function template specialization}} |
| 54 |
|