Clang Project

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