cpp_diagnostics.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/no_prelude/cpp_diagnostics.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/no_prelude/cpp_diagnostics.carbon
  10. // --- one_error.h
  11. #error "error1"
  12. // --- fail_import_cpp_file_with_one_error.carbon
  13. library "[[@TEST_NAME]]";
  14. // CHECK:STDERR: fail_import_cpp_file_with_one_error.carbon:[[@LINE+9]]:1: error: 1 error and 0 warnings in 1 `Cpp` import:
  15. // CHECK:STDERR: In file included from fail_import_cpp_file_with_one_error.carbon.generated.cpp_imports.h:1:
  16. // CHECK:STDERR: ./one_error.h:2:2: error: "error1"
  17. // CHECK:STDERR: 2 | #error "error1"
  18. // CHECK:STDERR: | ^
  19. // CHECK:STDERR: [CppInteropParseError]
  20. // CHECK:STDERR: import Cpp library "one_error.h";
  21. // CHECK:STDERR: ^~~~~~
  22. // CHECK:STDERR:
  23. import Cpp library "one_error.h";
  24. // --- multiple_errors.h
  25. #error "error1"
  26. #error "error2"
  27. // --- fail_import_cpp_file_with_multiple_errors.carbon
  28. library "[[@TEST_NAME]]";
  29. // CHECK:STDERR: fail_import_cpp_file_with_multiple_errors.carbon:[[@LINE+12]]:1: error: 2 errors and 0 warnings in 1 `Cpp` import:
  30. // CHECK:STDERR: In file included from fail_import_cpp_file_with_multiple_errors.carbon.generated.cpp_imports.h:1:
  31. // CHECK:STDERR: ./multiple_errors.h:2:2: error: "error1"
  32. // CHECK:STDERR: 2 | #error "error1"
  33. // CHECK:STDERR: | ^
  34. // CHECK:STDERR: ./multiple_errors.h:3:2: error: "error2"
  35. // CHECK:STDERR: 3 | #error "error2"
  36. // CHECK:STDERR: | ^
  37. // CHECK:STDERR: [CppInteropParseError]
  38. // CHECK:STDERR: import Cpp library "multiple_errors.h";
  39. // CHECK:STDERR: ^~~~~~
  40. // CHECK:STDERR:
  41. import Cpp library "multiple_errors.h";
  42. // --- one_warning.h
  43. #warning "warning1"
  44. // --- import_cpp_file_with_one_warning.carbon
  45. library "[[@TEST_NAME]]";
  46. // CHECK:STDERR: import_cpp_file_with_one_warning.carbon:[[@LINE+9]]:1: warning: 1 warning in `Cpp` 1 import:
  47. // CHECK:STDERR: In file included from import_cpp_file_with_one_warning.carbon.generated.cpp_imports.h:1:
  48. // CHECK:STDERR: ./one_warning.h:2:2: warning: "warning1"
  49. // CHECK:STDERR: 2 | #warning "warning1"
  50. // CHECK:STDERR: | ^
  51. // CHECK:STDERR: [CppInteropParseWarning]
  52. // CHECK:STDERR: import Cpp library "one_warning.h";
  53. // CHECK:STDERR: ^~~~~~
  54. // CHECK:STDERR:
  55. import Cpp library "one_warning.h";
  56. // --- multiple_warnings.h
  57. #warning "warning1"
  58. #warning "warning2"
  59. #warning "warning3"
  60. // --- import_cpp_file_with_multiple_warnings.carbon
  61. library "[[@TEST_NAME]]";
  62. // CHECK:STDERR: import_cpp_file_with_multiple_warnings.carbon:[[@LINE+15]]:1: warning: 3 warnings in `Cpp` 1 import:
  63. // CHECK:STDERR: In file included from import_cpp_file_with_multiple_warnings.carbon.generated.cpp_imports.h:1:
  64. // CHECK:STDERR: ./multiple_warnings.h:2:2: warning: "warning1"
  65. // CHECK:STDERR: 2 | #warning "warning1"
  66. // CHECK:STDERR: | ^
  67. // CHECK:STDERR: ./multiple_warnings.h:3:2: warning: "warning2"
  68. // CHECK:STDERR: 3 | #warning "warning2"
  69. // CHECK:STDERR: | ^
  70. // CHECK:STDERR: ./multiple_warnings.h:4:2: warning: "warning3"
  71. // CHECK:STDERR: 4 | #warning "warning3"
  72. // CHECK:STDERR: | ^
  73. // CHECK:STDERR: [CppInteropParseWarning]
  74. // CHECK:STDERR: import Cpp library "multiple_warnings.h";
  75. // CHECK:STDERR: ^~~~~~
  76. // CHECK:STDERR:
  77. import Cpp library "multiple_warnings.h";
  78. // --- one_error_and_one_warning.h
  79. #error "error1"
  80. #warning "warning1"
  81. // --- fail_import_cpp_file_with_one_error_and_one_warning.carbon
  82. library "[[@TEST_NAME]]";
  83. // CHECK:STDERR: fail_import_cpp_file_with_one_error_and_one_warning.carbon:[[@LINE+12]]:1: error: 1 error and 1 warning in 1 `Cpp` import:
  84. // CHECK:STDERR: In file included from fail_import_cpp_file_with_one_error_and_one_warning.carbon.generated.cpp_imports.h:1:
  85. // CHECK:STDERR: ./one_error_and_one_warning.h:2:2: error: "error1"
  86. // CHECK:STDERR: 2 | #error "error1"
  87. // CHECK:STDERR: | ^
  88. // CHECK:STDERR: ./one_error_and_one_warning.h:3:2: warning: "warning1"
  89. // CHECK:STDERR: 3 | #warning "warning1"
  90. // CHECK:STDERR: | ^
  91. // CHECK:STDERR: [CppInteropParseError]
  92. // CHECK:STDERR: import Cpp library "one_error_and_one_warning.h";
  93. // CHECK:STDERR: ^~~~~~
  94. // CHECK:STDERR:
  95. import Cpp library "one_error_and_one_warning.h";
  96. // --- multiple_errors_and_multiple_warnings.h
  97. #error "error1"
  98. #error "error2"
  99. #warning "warning1"
  100. #warning "warning2"
  101. #warning "warning3"
  102. // --- fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon
  103. library "[[@TEST_NAME]]";
  104. // CHECK:STDERR: fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon:[[@LINE+21]]:1: error: 2 errors and 3 warnings in 1 `Cpp` import:
  105. // CHECK:STDERR: In file included from fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon.generated.cpp_imports.h:1:
  106. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:2:2: error: "error1"
  107. // CHECK:STDERR: 2 | #error "error1"
  108. // CHECK:STDERR: | ^
  109. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:3:2: error: "error2"
  110. // CHECK:STDERR: 3 | #error "error2"
  111. // CHECK:STDERR: | ^
  112. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:4:2: warning: "warning1"
  113. // CHECK:STDERR: 4 | #warning "warning1"
  114. // CHECK:STDERR: | ^
  115. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:5:2: warning: "warning2"
  116. // CHECK:STDERR: 5 | #warning "warning2"
  117. // CHECK:STDERR: | ^
  118. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:6:2: warning: "warning3"
  119. // CHECK:STDERR: 6 | #warning "warning3"
  120. // CHECK:STDERR: | ^
  121. // CHECK:STDERR: [CppInteropParseError]
  122. // CHECK:STDERR: import Cpp library "multiple_errors_and_multiple_warnings.h";
  123. // CHECK:STDERR: ^~~~~~
  124. // CHECK:STDERR:
  125. import Cpp library "multiple_errors_and_multiple_warnings.h";
  126. // --- import_multiple_cpp_files_with_warnings.carbon
  127. library "[[@TEST_NAME]]";
  128. import Cpp library "one_warning.h";
  129. // CHECK:STDERR: import_multiple_cpp_files_with_warnings.carbon:[[@LINE+19]]:1: warning: 4 warnings in `Cpp` 2 imports:
  130. // CHECK:STDERR: In file included from import_multiple_cpp_files_with_warnings.carbon.generated.cpp_imports.h:1:
  131. // CHECK:STDERR: ./one_warning.h:2:2: warning: "warning1"
  132. // CHECK:STDERR: 2 | #warning "warning1"
  133. // CHECK:STDERR: | ^
  134. // CHECK:STDERR: In file included from import_multiple_cpp_files_with_warnings.carbon.generated.cpp_imports.h:2:
  135. // CHECK:STDERR: ./multiple_warnings.h:2:2: warning: "warning1"
  136. // CHECK:STDERR: 2 | #warning "warning1"
  137. // CHECK:STDERR: | ^
  138. // CHECK:STDERR: ./multiple_warnings.h:3:2: warning: "warning2"
  139. // CHECK:STDERR: 3 | #warning "warning2"
  140. // CHECK:STDERR: | ^
  141. // CHECK:STDERR: ./multiple_warnings.h:4:2: warning: "warning3"
  142. // CHECK:STDERR: 4 | #warning "warning3"
  143. // CHECK:STDERR: | ^
  144. // CHECK:STDERR: [CppInteropParseWarning]
  145. // CHECK:STDERR: import Cpp library "multiple_warnings.h";
  146. // CHECK:STDERR: ^~~~~~
  147. // CHECK:STDERR:
  148. import Cpp library "multiple_warnings.h";
  149. // --- fail_import_multiple_cpp_files_with_warnings_and_errors.carbon
  150. library "[[@TEST_NAME]]";
  151. import Cpp library "one_error_and_one_warning.h";
  152. // CHECK:STDERR: fail_import_multiple_cpp_files_with_warnings_and_errors.carbon:[[@LINE+28]]:1: error: 3 errors and 4 warnings in 2 `Cpp` imports:
  153. // CHECK:STDERR: In file included from fail_import_multiple_cpp_files_with_warnings_and_errors.carbon.generated.cpp_imports.h:1:
  154. // CHECK:STDERR: ./one_error_and_one_warning.h:2:2: error: "error1"
  155. // CHECK:STDERR: 2 | #error "error1"
  156. // CHECK:STDERR: | ^
  157. // CHECK:STDERR: ./one_error_and_one_warning.h:3:2: warning: "warning1"
  158. // CHECK:STDERR: 3 | #warning "warning1"
  159. // CHECK:STDERR: | ^
  160. // CHECK:STDERR: In file included from fail_import_multiple_cpp_files_with_warnings_and_errors.carbon.generated.cpp_imports.h:2:
  161. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:2:2: error: "error1"
  162. // CHECK:STDERR: 2 | #error "error1"
  163. // CHECK:STDERR: | ^
  164. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:3:2: error: "error2"
  165. // CHECK:STDERR: 3 | #error "error2"
  166. // CHECK:STDERR: | ^
  167. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:4:2: warning: "warning1"
  168. // CHECK:STDERR: 4 | #warning "warning1"
  169. // CHECK:STDERR: | ^
  170. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:5:2: warning: "warning2"
  171. // CHECK:STDERR: 5 | #warning "warning2"
  172. // CHECK:STDERR: | ^
  173. // CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:6:2: warning: "warning3"
  174. // CHECK:STDERR: 6 | #warning "warning3"
  175. // CHECK:STDERR: | ^
  176. // CHECK:STDERR: [CppInteropParseError]
  177. // CHECK:STDERR: import Cpp library "multiple_errors_and_multiple_warnings.h";
  178. // CHECK:STDERR: ^~~~~~
  179. // CHECK:STDERR:
  180. import Cpp library "multiple_errors_and_multiple_warnings.h";
  181. // CHECK:STDOUT: --- fail_import_cpp_file_with_one_error.carbon
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: file {
  184. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  185. // CHECK:STDOUT: }
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: --- fail_import_cpp_file_with_multiple_errors.carbon
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: file {
  190. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: --- import_cpp_file_with_one_warning.carbon
  194. // CHECK:STDOUT:
  195. // CHECK:STDOUT: file {
  196. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: --- import_cpp_file_with_multiple_warnings.carbon
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: file {
  202. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: --- fail_import_cpp_file_with_one_error_and_one_warning.carbon
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: file {
  208. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: --- fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: file {
  214. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  215. // CHECK:STDOUT: }
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: --- import_multiple_cpp_files_with_warnings.carbon
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: file {
  220. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  221. // CHECK:STDOUT: }
  222. // CHECK:STDOUT:
  223. // CHECK:STDOUT: --- fail_import_multiple_cpp_files_with_warnings_and_errors.carbon
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: file {
  226. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT: