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