captured-stmt.cpp 595 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // RUN: %clang_cc1 -x c++-header -emit-pch %s -o %t
  2. // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s
  3. // expected-no-diagnostics
  4. #ifndef HEADER_INCLUDED
  5. #define HEADER_INCLUDED
  6. static inline void foo(int &x, int y) {
  7. // Capturing x and y
  8. #pragma clang __debug captured
  9. {
  10. x += y;
  11. }
  12. }
  13. struct C {
  14. int val;
  15. explicit C(int v) : val(v) { }
  16. void bar(int &x) {
  17. // Capturing x and this
  18. #pragma clang __debug captured
  19. {
  20. x += val;
  21. }
  22. }
  23. };
  24. #else
  25. void test_foo(int &x) {
  26. foo(x, 10);
  27. }
  28. void test_bar(int &x) {
  29. C Obj(10);
  30. Obj.bar(x);
  31. }
  32. #endif