class.carbon 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/reverse/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/reverse/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. // --- fail_incomplete_concrete.carbon
  38. library "[[@TEST_NAME]]";
  39. import Cpp;
  40. // CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+4]]:1: error: class was forward declared here [ClassForwardDeclaredHere]
  41. // CHECK:STDERR: class A;
  42. // CHECK:STDERR: ^~~~~~~~
  43. // CHECK:STDERR:
  44. class A;
  45. inline Cpp '''
  46. // CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+4]]:11: error: variable has incomplete type 'Carbon::A' [CppInteropParseError]
  47. // CHECK:STDERR: 16 | Carbon::A a;
  48. // CHECK:STDERR: | ^
  49. // CHECK:STDERR:
  50. Carbon::A a;
  51. ''';
  52. // --- fail_todo_monomorphization_failure.carbon
  53. library "[[@TEST_NAME]]";
  54. import Cpp;
  55. class B(N:! i32) {
  56. var a: array(i8, N);
  57. }
  58. // TODO: Once we allow this, we should produce an "invalid array bound" error
  59. // during monomorphization triggered by the C++ code.
  60. // CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+4]]:11: error: alias initializer must be a name reference [AliasRequiresNameRef]
  61. // CHECK:STDERR: alias T = B(-1);
  62. // CHECK:STDERR: ^~~~~
  63. // CHECK:STDERR:
  64. alias T = B(-1);
  65. inline Cpp '''
  66. // CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+4]]:9: error: no type named 'T' in namespace 'Carbon' [CppInteropParseError]
  67. // CHECK:STDERR: 22 | Carbon::T t;
  68. // CHECK:STDERR: | ~~~~~~~~^
  69. // CHECK:STDERR:
  70. Carbon::T t;
  71. ''';
  72. // --- fail_todo_fields.carbon
  73. library "[[@TEST_NAME]]";
  74. import Cpp;
  75. class A {
  76. var a: i32;
  77. var b: i32;
  78. }
  79. inline Cpp '''
  80. // CHECK:STDERR: fail_todo_fields.carbon:[[@LINE+7]]:15: error: static assertion failed due to requirement 'sizeof(Carbon::A) == 2 * sizeof(int)' [CppInteropParseError]
  81. // CHECK:STDERR: 18 | static_assert(sizeof(Carbon::A) == 2 * sizeof(int));
  82. // CHECK:STDERR: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. // CHECK:STDERR: fail_todo_fields.carbon:[[@LINE+4]]:33: note: expression evaluates to '1 == 8' [CppInteropParseNote]
  84. // CHECK:STDERR: 18 | static_assert(sizeof(Carbon::A) == 2 * sizeof(int));
  85. // CHECK:STDERR: | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
  86. // CHECK:STDERR:
  87. static_assert(sizeof(Carbon::A) == 2 * sizeof(int));
  88. ''';