decl.carbon 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/none.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/basics/inline/decl.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/inline/decl.carbon
  12. // --- inline_decl.carbon
  13. library "[[@TEST_NAME]]";
  14. import Cpp;
  15. inline Cpp '''
  16. void func1() {}
  17. ''';
  18. fn Run1() {
  19. Cpp.func1();
  20. }
  21. inline Cpp '''
  22. void func2() {
  23. Carbon::Run1();
  24. }
  25. ''';
  26. fn Run2() {
  27. Cpp.func2();
  28. }
  29. // --- fail_redefinition.carbon
  30. library "[[@TEST_NAME]]";
  31. import Cpp;
  32. inline Cpp '''
  33. void f() {}
  34. ''';
  35. inline Cpp '''
  36. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE+7]]:6: error: redefinition of 'f' [CppInteropParseError]
  37. // CHECK:STDERR: 18 | void f() {}
  38. // CHECK:STDERR: | ^
  39. // CHECK:STDERR: fail_redefinition.carbon:[[@LINE-7]]:6: note: previous definition is here [CppInteropParseNote]
  40. // CHECK:STDERR: 7 | void f() {}
  41. // CHECK:STDERR: | ^
  42. // CHECK:STDERR:
  43. void f() {}
  44. ''';
  45. // --- fail_diag_location.carbon
  46. library "[[@TEST_NAME]]";
  47. import Cpp;
  48. // CHECK:STDERR: fail_diag_location.carbon:[[@LINE+4]]:12: error: use of undeclared identifier 'undeclared' [CppInteropParseError]
  49. // CHECK:STDERR: 10 | void f() { undeclared = 0; }
  50. // CHECK:STDERR: | ^~~~~~~~~~
  51. // CHECK:STDERR:
  52. inline Cpp "void f() { undeclared = 0; }";
  53. inline Cpp '''
  54. void g() {
  55. // CHECK:STDERR: fail_diag_location.carbon:[[@LINE+4]]:3: error: use of undeclared identifier 'undeclared' [CppInteropParseError]
  56. // CHECK:STDERR: 18 | undeclared = 0;
  57. // CHECK:STDERR: | ^~~~~~~~~~
  58. // CHECK:STDERR:
  59. undeclared = 0;
  60. }
  61. ''';
  62. // --- fail_inline_no_import.carbon
  63. library "[[@TEST_NAME]]";
  64. // CHECK:STDERR: fail_inline_no_import.carbon:[[@LINE+4]]:8: error: name `Cpp` not found [NameNotFound]
  65. // CHECK:STDERR: inline Cpp "";
  66. // CHECK:STDERR: ^~~
  67. // CHECK:STDERR:
  68. inline Cpp "";
  69. // --- fail_nested.carbon
  70. library "[[@TEST_NAME]]";
  71. import Cpp;
  72. class C {
  73. // CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:3: error: `inline Cpp` declaration not at file scope [InlineDeclNotAtFileScope]
  74. // CHECK:STDERR: inline Cpp "";
  75. // CHECK:STDERR: ^~~~~~~~~~~~~~
  76. // CHECK:STDERR:
  77. inline Cpp "";
  78. }
  79. interface I {
  80. // CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:3: error: `inline Cpp` declaration not at file scope [InlineDeclNotAtFileScope]
  81. // CHECK:STDERR: inline Cpp "";
  82. // CHECK:STDERR: ^~~~~~~~~~~~~~
  83. // CHECK:STDERR:
  84. inline Cpp "";
  85. }
  86. constraint N {
  87. // CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:3: error: `inline Cpp` declaration not at file scope [InlineDeclNotAtFileScope]
  88. // CHECK:STDERR: inline Cpp "";
  89. // CHECK:STDERR: ^~~~~~~~~~~~~~
  90. // CHECK:STDERR:
  91. inline Cpp "";
  92. }
  93. impl C as I {
  94. // CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:3: error: `inline Cpp` declaration not at file scope [InlineDeclNotAtFileScope]
  95. // CHECK:STDERR: inline Cpp "";
  96. // CHECK:STDERR: ^~~~~~~~~~~~~~
  97. // CHECK:STDERR:
  98. inline Cpp "";
  99. }
  100. // --- fail_nested_fn.carbon
  101. fn F() {
  102. // TODO: Should this be a check error rather than a parse error?
  103. // CHECK:STDERR: fail_nested_fn.carbon:[[@LINE+8]]:3: error: expected expression [ExpectedExpr]
  104. // CHECK:STDERR: inline Cpp "";
  105. // CHECK:STDERR: ^~~~~~
  106. // CHECK:STDERR:
  107. // CHECK:STDERR: fail_nested_fn.carbon:[[@LINE+4]]:3: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  108. // CHECK:STDERR: inline Cpp "";
  109. // CHECK:STDERR: ^~~~~~
  110. // CHECK:STDERR:
  111. inline Cpp "";
  112. }