blob: b66825a536dc3939b7df65135325df5f42847984 [file] [log] [blame]
Rafael Espindolaf003acd2013-10-04 14:28:51 +00001// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks %s
Faisal Valid6992ab2013-09-29 08:45:24 +00002// DONTRUNYET: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
3// DONTRUNYET: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fms-extensions %s -DMS_EXTENSIONS
4// DONTRUNYET: %clang_cc1 -std=c++1y -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING
5
6namespace explicit_call {
7int test() {
8 auto L = [](auto a) { return a; };
9 L.operator()(3);
10 L.operator()<char>(3.14); //expected-warning{{implicit conversion}}
11 return 0;
12}
13} //end ns
14
15namespace test_conversion_to_fptr {
16
17void f1(int (*)(int)) { }
18void f2(char (*)(int)) { } // expected-note{{candidate}}
19void g(int (*)(int)) { } // #1 expected-note{{candidate}}
20void g(char (*)(char)) { } // #2 expected-note{{candidate}}
21void h(int (*)(int)) { } // #3
22void h(char (*)(int)) { } // #4
23
24int test() {
25{
26 auto glambda = [](auto a) { return a; };
27 glambda(1);
28 f1(glambda); // OK
29 f2(glambda); // expected-error{{no matching function}}
30 g(glambda); // expected-error{{call to 'g' is ambiguous}}
31 h(glambda); // OK: calls #3 since it is convertible from ID
32
33 int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
34
35}
36{
37
38 auto L = [](auto a) { return a; };
39 int (*fp)(int) = L;
40 fp(5);
41 L(3);
42 char (*fc)(char) = L;
43 fc('b');
44 L('c');
45 double (*fd)(double) = L;
46 fd(3.14);
47 fd(6.26);
48 L(4.25);
49}
50{
51 auto L = [](auto a) ->int { return a; }; //expected-note 2{{candidate template ignored}}
52 int (*fp)(int) = L;
53 char (*fc)(char) = L; //expected-error{{no viable conversion}}
54 double (*fd)(double) = L; //expected-error{{no viable conversion}}
55}
56
57}
58
59namespace more_converion_to_ptr_to_function_tests {
60
61
62int test() {
63 {
64 int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
65 int (*fp2)(int) = [](auto b) -> int { return b; };
66 int (*fp3)(char) = [](auto c) -> int { return c; };
67 char (*fp4)(int) = [](auto d) { return d; }; //expected-error{{no viable conversion}}\
68 //expected-note{{candidate template ignored}}
69 char (*fp5)(char) = [](auto e) -> int { return e; }; //expected-error{{no viable conversion}}\
70 //expected-note{{candidate template ignored}}
71
72 fp2(3);
73 fp3('\n');
74 fp3('a');
75 return 0;
76 }
77} // end test()
78
79template<class ... Ts> void vfun(Ts ... ) { }
80
81int variadic_test() {
82
83 int (*fp)(int, char, double) = [](auto ... a) -> int { vfun(a...); return 4; };
84 fp(3, '4', 3.14);
85
86 int (*fp2)(int, char, double) = [](auto ... a) { vfun(a...); return 4; };
87 fp(3, '4', 3.14);
88 return 2;
89}
90
91} // end ns
92
93namespace conversion_operator {
94void test() {
95 auto L = [](auto a) -> int { return a; };
96 int (*fp)(int) = L;
97 int (&fp2)(int) = [](auto a) { return a; }; // expected-error{{non-const lvalue}}
98 int (&&fp3)(int) = [](auto a) { return a; }; // expected-error{{no viable conversion}}\
99 //expected-note{{candidate}}
100 }
101}
Rafael Espindolaf003acd2013-10-04 14:28:51 +0000102
Faisal Valid6992ab2013-09-29 08:45:24 +0000103}
104
Rafael Espindolaf003acd2013-10-04 14:28:51 +0000105
Faisal Valid6992ab2013-09-29 08:45:24 +0000106namespace return_type_deduction_ok {
107 auto l = [](auto a) ->auto { return a; }(2);
108 auto l2 = [](auto a) ->decltype(auto) { return a; }(2);
109 auto l3 = [](auto a) { return a; }(2);
110
111}
112
113namespace generic_lambda_as_default_argument_ok {
114 void test(int i = [](auto a)->int { return a; }(3)) {
115 }
116}