xref: /llvm-project/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p6.cpp (revision 6976fef05b7e5301815baa6cc4af27284e8aceb4)
1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2 // RUN: %clang_cc1 -fsyntax-only -std=c++1z %s -verify
3 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -triple i386-windows-pc -verify
4 // RUN: %clang_cc1 -fsyntax-only -std=c++1z %s -triple i386-windows-pc -verify
5 
test_conversion()6 void test_conversion() {
7   int (*fp1)(int) = [](int x) { return x + 1; };
8   void (*fp2)(int) = [](int x) { };
9 
10   const auto lambda = [](int x) { };
11   void (*fp3)(int) = lambda;
12 
13   volatile const auto lambda2 = [](int x) { }; // expected-note{{but method is not marked volatile}}
14   void (*fp4)(int) = lambda2; // expected-error{{no viable conversion}}
15 
16   void (*fp5)(int) noexcept = [](int x) { };
17 #if __cplusplus > 201402L
18   // expected-error@-2 {{no viable}} expected-note@-2 {{candidate}}
19   void (*fp5a)(int) noexcept = [](auto x) { };
20   // expected-error@-1 {{no viable}} expected-note@-1 {{candidate}}
21   void (*fp5b)(int) noexcept = [](auto x) noexcept { };
22 #endif
23   void (*fp6)(int) noexcept = [](int x) noexcept { };
24 }
25 
test_no_conversion()26 void test_no_conversion() {
27   int (*fp1)(int) = [=](int x) { return x + 1; }; // expected-error{{no viable conversion}}
28   void (*fp2)(int) = [&](int x) { }; // expected-error{{no viable conversion}}
29 }
30 
test_wonky()31 void test_wonky() {
32   const auto l = [](int x) mutable -> int { return + 1; };
33   l(17); // okay: uses conversion function
34 }
35