class.carbon 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/class.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/class.carbon
  12. // --- static_members.carbon
  13. library "[[@TEST_NAME]]";
  14. import Cpp;
  15. class A {
  16. fn F() {}
  17. }
  18. inline Cpp '''
  19. void G() {
  20. Carbon::A::F();
  21. }
  22. ''';
  23. // --- nested.carbon
  24. library "[[@TEST_NAME]]";
  25. import Cpp;
  26. class A {
  27. class B {
  28. class C {
  29. }
  30. }
  31. }
  32. inline Cpp '''
  33. void G() {
  34. Carbon::A::B::C *p = nullptr;
  35. }
  36. ''';
  37. // --- incomplete.carbon
  38. library "[[@TEST_NAME]]";
  39. import Cpp;
  40. class A;
  41. inline Cpp '''
  42. Carbon::A *p = nullptr;
  43. ''';
  44. // --- fail_incomplete_concrete.carbon
  45. library "[[@TEST_NAME]]";
  46. import Cpp;
  47. // CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+4]]:1: error: class was forward declared here [ClassForwardDeclaredHere]
  48. // CHECK:STDERR: class A;
  49. // CHECK:STDERR: ^~~~~~~~
  50. // CHECK:STDERR:
  51. class A;
  52. inline Cpp '''
  53. // CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+4]]:11: error: variable has incomplete type 'Carbon::A' [CppInteropParseError]
  54. // CHECK:STDERR: 16 | Carbon::A a;
  55. // CHECK:STDERR: | ^
  56. // CHECK:STDERR:
  57. Carbon::A a;
  58. ''';
  59. // --- fail_todo_monomorphization_failure.carbon
  60. library "[[@TEST_NAME]]";
  61. import Cpp;
  62. class B(N:! i32) {
  63. var a: array(i8, N);
  64. }
  65. // TODO: Once we allow this, we should produce an "invalid array bound" error
  66. // during monomorphization triggered by the C++ code.
  67. // CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+4]]:11: error: alias initializer must be a name reference [AliasRequiresNameRef]
  68. // CHECK:STDERR: alias T = B(-1);
  69. // CHECK:STDERR: ^~~~~
  70. // CHECK:STDERR:
  71. alias T = B(-1);
  72. inline Cpp '''
  73. // CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+4]]:9: error: no type named 'T' in namespace 'Carbon' [CppInteropParseError]
  74. // CHECK:STDERR: 22 | Carbon::T t;
  75. // CHECK:STDERR: | ~~~~~~~~^
  76. // CHECK:STDERR:
  77. Carbon::T t;
  78. ''';