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