method.carbon 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // EXTRA-ARGS: --clang-arg=-std=c++26
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/interop/cpp/method.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/method.carbon
  13. // TODO: Tests marked as `fail_todo_5891_` to fixed as a follow-up of https://github.com/carbon-language/carbon-lang/pull/5891.
  14. // --- methods.h
  15. struct A {
  16. int by_val() const { return n; }
  17. int by_ref() { return n; }
  18. int n;
  19. };
  20. // --- fail_todo_5891_call_by_val.carbon
  21. library "[[@TEST_NAME]]";
  22. import Cpp library "methods.h";
  23. fn UseVal(a: Cpp.A) -> i32 {
  24. // CHECK:STDERR: fail_todo_5891_call_by_val.carbon:[[@LINE+5]]:10: error: missing object argument in method call [MissingObjectInMethodCall]
  25. // CHECK:STDERR: return a.by_val();
  26. // CHECK:STDERR: ^~~~~~~~~~
  27. // CHECK:STDERR: fail_todo_5891_call_by_val.carbon: note: calling function declared here [InCallToFunction]
  28. // CHECK:STDERR:
  29. return a.by_val();
  30. }
  31. // --- fail_todo_5891_call_by_ref.carbon
  32. library "[[@TEST_NAME]]";
  33. import Cpp library "methods.h";
  34. fn UseVal(a: Cpp.A*) -> i32 {
  35. // CHECK:STDERR: fail_todo_5891_call_by_ref.carbon:[[@LINE+5]]:10: error: missing object argument in method call [MissingObjectInMethodCall]
  36. // CHECK:STDERR: return a->by_ref();
  37. // CHECK:STDERR: ^~~~~~~~~~~
  38. // CHECK:STDERR: fail_todo_5891_call_by_ref.carbon: note: calling function declared here [InCallToFunction]
  39. // CHECK:STDERR:
  40. return a->by_ref();
  41. }
  42. // --- thunk.h
  43. struct NeedThunk {
  44. void Implicit(signed char c) const;
  45. void Explicit(this NeedThunk, signed char c);
  46. };
  47. // --- fail_todo_5891_call_thunk.carbon
  48. library "[[@TEST_NAME]]";
  49. import Cpp library "thunk.h";
  50. fn Call(n: Cpp.NeedThunk) {
  51. // CHECK:STDERR: fail_todo_5891_call_thunk.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall]
  52. // CHECK:STDERR: n.Implicit(1);
  53. // CHECK:STDERR: ^~~~~~~~~~~~~
  54. // CHECK:STDERR: fail_todo_5891_call_thunk.carbon: note: calling function declared here [InCallToFunction]
  55. // CHECK:STDERR:
  56. n.Implicit(1);
  57. // CHECK:STDERR: fail_todo_5891_call_thunk.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall]
  58. // CHECK:STDERR: n.Explicit(1);
  59. // CHECK:STDERR: ^~~~~~~~~~~~~
  60. // CHECK:STDERR: fail_todo_5891_call_thunk.carbon: note: calling function declared here [InCallToFunction]
  61. // CHECK:STDERR:
  62. n.Explicit(1);
  63. }