method.carbon 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/export/method.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/export/method.carbon
  12. // --- static_method.carbon
  13. library "[[@TEST_NAME]]";
  14. import Cpp;
  15. class C {
  16. fn M();
  17. }
  18. inline Cpp '''
  19. void F() {
  20. Carbon::C::M();
  21. }
  22. ''';
  23. // --- method_lvalue.carbon
  24. library "[[@TEST_NAME]]";
  25. import Cpp;
  26. class C {
  27. fn M[self: Self]();
  28. }
  29. inline Cpp '''
  30. void F() {
  31. Carbon::C c;
  32. c.M();
  33. }
  34. ''';
  35. // --- method_rvalue.carbon
  36. library "[[@TEST_NAME]]";
  37. import Cpp;
  38. class C {
  39. fn M[self: Self]();
  40. }
  41. inline Cpp '''
  42. void F() {
  43. Carbon::C().M();
  44. }
  45. ''';
  46. // --- ref_method_lvalue.carbon
  47. library "[[@TEST_NAME]]";
  48. import Cpp;
  49. class C {
  50. fn M[ref self: Self]();
  51. }
  52. inline Cpp '''
  53. void F() {
  54. Carbon::C c;
  55. c.M();
  56. }
  57. ''';
  58. // --- todo_ref_method_rvalue.carbon
  59. library "[[@TEST_NAME]]";
  60. import Cpp;
  61. class C {
  62. fn M[ref self: Self]();
  63. }
  64. inline Cpp '''
  65. void F() {
  66. // TODO: this should be disallowed.
  67. Carbon::C().M();
  68. }
  69. ''';