1*a72f11eeSErich Keane // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2*a72f11eeSErich Keane // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -triple i386-windows
3adb376ecSDouglas Gregor
defargs()4adb376ecSDouglas Gregor void defargs() {
5adb376ecSDouglas Gregor auto l1 = [](int i, int j = 17, int k = 18) { return i + j + k; };
6adb376ecSDouglas Gregor int i1 = l1(1);
7adb376ecSDouglas Gregor int i2 = l1(1, 2);
8adb376ecSDouglas Gregor int i3 = l1(1, 2, 3);
9adb376ecSDouglas Gregor }
10adb376ecSDouglas Gregor
11adb376ecSDouglas Gregor
defargs_errors()12adb376ecSDouglas Gregor void defargs_errors() {
13adb376ecSDouglas Gregor auto l1 = [](int i,
14adb376ecSDouglas Gregor int j = 17,
15adb376ecSDouglas Gregor int k) { }; // expected-error{{missing default argument on parameter 'k'}}
16adb376ecSDouglas Gregor
17adb376ecSDouglas Gregor auto l2 = [](int i, int j = i) {}; // expected-error{{default argument references parameter 'i'}}
18adb376ecSDouglas Gregor
19adb376ecSDouglas Gregor int foo;
20adb376ecSDouglas Gregor auto l3 = [](int i = foo) {}; // expected-error{{default argument references local variable 'foo' of enclosing function}}
21adb376ecSDouglas Gregor }
22adb376ecSDouglas Gregor
23adb376ecSDouglas Gregor struct NonPOD {
24adb376ecSDouglas Gregor NonPOD();
25adb376ecSDouglas Gregor NonPOD(const NonPOD&);
26adb376ecSDouglas Gregor ~NonPOD();
27adb376ecSDouglas Gregor };
28adb376ecSDouglas Gregor
29adb376ecSDouglas Gregor struct NoDefaultCtor {
3073c6a244SSerge Pavlov NoDefaultCtor(const NoDefaultCtor&); // expected-note{{candidate constructor}} \
3173c6a244SSerge Pavlov // expected-note{{candidate constructor not viable: requires 1 argument, but 0 were provided}}
32adb376ecSDouglas Gregor ~NoDefaultCtor();
33adb376ecSDouglas Gregor };
34adb376ecSDouglas Gregor
35adb376ecSDouglas Gregor template<typename T>
defargs_in_template_unused(T t)36adb376ecSDouglas Gregor void defargs_in_template_unused(T t) {
3773c6a244SSerge Pavlov auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}}
38adb376ecSDouglas Gregor l1(t);
39adb376ecSDouglas Gregor }
40adb376ecSDouglas Gregor
41adb376ecSDouglas Gregor template void defargs_in_template_unused(NonPOD);
4273c6a244SSerge Pavlov template void defargs_in_template_unused(NoDefaultCtor); // expected-note{{in instantiation of function template specialization 'defargs_in_template_unused<NoDefaultCtor>' requested here}}
43adb376ecSDouglas Gregor
44adb376ecSDouglas Gregor template<typename T>
defargs_in_template_used()45adb376ecSDouglas Gregor void defargs_in_template_used() {
4673c6a244SSerge Pavlov auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}} \
47*a72f11eeSErich Keane // expected-note{{candidate function not viable: requires single argument 'value', but no arguments were provided}}
48*a72f11eeSErich Keane #if defined(_WIN32) && !defined(_WIN64)
49*a72f11eeSErich Keane // expected-note@46{{conversion candidate of type 'void (*)(const NoDefaultCtor &) __attribute__((thiscall))'}}
50*a72f11eeSErich Keane #else
51*a72f11eeSErich Keane // expected-note@46{{conversion candidate of type 'void (*)(const NoDefaultCtor &)'}}
52*a72f11eeSErich Keane #endif
5373c6a244SSerge Pavlov l1(); // expected-error{{no matching function for call to object of type '(lambda at }}
54adb376ecSDouglas Gregor }
55adb376ecSDouglas Gregor
56adb376ecSDouglas Gregor template void defargs_in_template_used<NonPOD>();
57adb376ecSDouglas Gregor template void defargs_in_template_used<NoDefaultCtor>(); // expected-note{{in instantiation of function template specialization}}
58adb376ecSDouglas Gregor
59