base.carbon 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/lower/testdata/interop/cpp/base.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/base.carbon
  12. // TODO: Tests marked as `fail_todo_5891_` to fixed as a follow-up of https://github.com/carbon-language/carbon-lang/pull/5891.
  13. // --- structs.h
  14. struct A {
  15. int a;
  16. void f() {}
  17. };
  18. struct B : A {
  19. int b;
  20. };
  21. // --- convert.carbon
  22. library "[[@TEST_NAME]]";
  23. import Cpp library "structs.h";
  24. fn ConvertPtr(p: Cpp.B*) -> Cpp.A* {
  25. return p;
  26. }
  27. fn AcceptVal(a: Cpp.A);
  28. fn ConvertVal(b: Cpp.B) {
  29. AcceptVal(b);
  30. }
  31. // --- access_field.carbon
  32. library "[[@TEST_NAME]]";
  33. import Cpp library "structs.h";
  34. fn AccessVal(b: Cpp.B) -> i32 {
  35. return b.a;
  36. }
  37. // --- fail_todo_5891_call_method.carbon
  38. library "[[@TEST_NAME]]";
  39. import Cpp library "structs.h";
  40. fn Call(b: Cpp.B*) {
  41. // CHECK:STDERR: fail_todo_5891_call_method.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall]
  42. // CHECK:STDERR: b->f();
  43. // CHECK:STDERR: ^~~~~~
  44. // CHECK:STDERR: fail_todo_5891_call_method.carbon: note: calling function declared here [InCallToFunction]
  45. // CHECK:STDERR:
  46. b->f();
  47. }