p7.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
  2. // Check that analysis-based warnings work in lambda bodies.
  3. void analysis_based_warnings() {
  4. (void)[]() -> int { }; // expected-warning{{control reaches end of non-void lambda}}
  5. }
  6. // Check that we get the right types of captured variables (the
  7. // semantic-analysis part of p7).
  8. int &check_const_int(int&);
  9. float &check_const_int(const int&);
  10. void test_capture_constness(int i, const int ic) {
  11. (void)[i,ic] ()->void {
  12. float &fr1 = check_const_int(i);
  13. float &fr2 = check_const_int(ic);
  14. };
  15. (void)[=] ()->void {
  16. float &fr1 = check_const_int(i);
  17. float &fr2 = check_const_int(ic);
  18. };
  19. (void)[i,ic] () mutable ->void {
  20. int &ir = check_const_int(i);
  21. float &fr = check_const_int(ic);
  22. };
  23. (void)[=] () mutable ->void {
  24. int &ir = check_const_int(i);
  25. float &fr = check_const_int(ic);
  26. };
  27. (void)[&i,&ic] ()->void {
  28. int &ir = check_const_int(i);
  29. float &fr = check_const_int(ic);
  30. };
  31. (void)[&] ()->void {
  32. int &ir = check_const_int(i);
  33. float &fr = check_const_int(ic);
  34. };
  35. }
  36. struct S1 {
  37. int x, y;
  38. S1 &operator=(int*);
  39. int operator()(int);
  40. void f() {
  41. [&]()->int {
  42. S1 &s1 = operator=(&this->x);
  43. return operator()(this->x + y);
  44. }();
  45. }
  46. };