p6.cpp 737 B

12345678910111213141516171819202122
  1. // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
  2. void test_conversion() {
  3. int (*fp1)(int) = [](int x) { return x + 1; };
  4. void (*fp2)(int) = [](int x) { };
  5. const auto lambda = [](int x) { };
  6. void (*fp3)(int) = lambda;
  7. volatile const auto lambda2 = [](int x) { }; // expected-note{{but method is not marked volatile}}
  8. void (*fp4)(int) = lambda2; // expected-error{{no viable conversion}}
  9. }
  10. void test_no_conversion() {
  11. int (*fp1)(int) = [=](int x) { return x + 1; }; // expected-error{{no viable conversion}}
  12. void (*fp2)(int) = [&](int x) { }; // expected-error{{no viable conversion}}
  13. }
  14. void test_wonky() {
  15. const auto l = [](int x) mutable -> int { return + 1; };
  16. l(17); // okay: uses conversion function
  17. }