p14.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
  2. template<typename T> void capture(const T&);
  3. class NonCopyable {
  4. NonCopyable(const NonCopyable&); // expected-note 2 {{implicitly declared private here}}
  5. public:
  6. void foo() const;
  7. };
  8. void capture_by_copy(NonCopyable nc, NonCopyable &ncr) {
  9. (void)[nc] { }; // expected-error{{capture of variable 'nc' as type 'NonCopyable' calls private copy constructor}}
  10. (void)[=] {
  11. ncr.foo(); // expected-error{{capture of variable 'ncr' as type 'NonCopyable' calls private copy constructor}}
  12. }();
  13. }
  14. struct NonTrivial {
  15. NonTrivial();
  16. NonTrivial(const NonTrivial &);
  17. ~NonTrivial();
  18. };
  19. struct CopyCtorDefault {
  20. CopyCtorDefault();
  21. CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial());
  22. void foo() const;
  23. };
  24. void capture_with_default_args(CopyCtorDefault cct) {
  25. (void)[=] () -> void { cct.foo(); };
  26. }
  27. struct ExpectedArrayLayout {
  28. CopyCtorDefault array[3];
  29. };
  30. void capture_array() {
  31. CopyCtorDefault array[3];
  32. auto x = [=]() -> void {
  33. capture(array[0]);
  34. };
  35. static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch");
  36. }
  37. // Check for the expected non-static data members.
  38. struct ExpectedLayout {
  39. char a;
  40. short b;
  41. };
  42. void test_layout(char a, short b) {
  43. auto x = [=] () -> void {
  44. capture(a);
  45. capture(b);
  46. };
  47. static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!");
  48. }
  49. struct ExpectedThisLayout {
  50. ExpectedThisLayout* a;
  51. void f() {
  52. auto x = [this]() -> void {};
  53. static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!");
  54. }
  55. };