fail_extern_c.carbon 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/full.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/fail_extern_c.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/fail_extern_c.carbon
  12. // These tests were factored out of `extern_c.carbon` because we do not generate
  13. // LLVM IR if any test contains errors. They should be moved back once they can
  14. // successfully compile.
  15. // ============================================================================
  16. // extern "C" variable
  17. // ============================================================================
  18. // --- extern_c_variable.h
  19. extern "C" int foo;
  20. // --- fail_todo_import_extern_c_variable.carbon
  21. library "[[@TEST_NAME]]";
  22. // CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+4]]:10: in file included here [InCppInclude]
  23. // CHECK:STDERR: ./extern_c_variable.h:2:16: error: semantics TODO: `Unsupported: Declaration type Var` [SemanticsTodo]
  24. // CHECK:STDERR: extern "C" int foo;
  25. // CHECK:STDERR: ^
  26. import Cpp library "extern_c_variable.h";
  27. fn MyF() -> i32 {
  28. // CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+4]]:10: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
  29. // CHECK:STDERR: return Cpp.foo;
  30. // CHECK:STDERR: ^~~~~~~
  31. // CHECK:STDERR:
  32. return Cpp.foo;
  33. }
  34. // ============================================================================
  35. // extern "C" function with C++ special name
  36. // ============================================================================
  37. // --- extern_c_with_special_name.h
  38. struct X {};
  39. extern "C" X operator+(X, X);
  40. // --- import_extern_c_with_special_name.carbon
  41. library "[[@TEST_NAME]]";
  42. import Cpp library "extern_c_with_special_name.h";
  43. fn MyF(a: Cpp.X, b: Cpp.X) -> Cpp.X {
  44. return a + b;
  45. }