fail_extern_c.carbon 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. import Cpp library "extern_c_variable.h";
  23. fn MyF() -> i32 {
  24. // CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+11]]:10: error: semantics TODO: `Unsupported: Declaration type Var` [SemanticsTodo]
  25. // CHECK:STDERR: return Cpp.foo;
  26. // CHECK:STDERR: ^~~~~~~
  27. // CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+8]]:10: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
  28. // CHECK:STDERR: return Cpp.foo;
  29. // CHECK:STDERR: ^~~~~~~
  30. // CHECK:STDERR:
  31. // CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+4]]:10: error: member name `foo` not found in `Cpp` [MemberNameNotFoundInInstScope]
  32. // CHECK:STDERR: return Cpp.foo;
  33. // CHECK:STDERR: ^~~~~~~
  34. // CHECK:STDERR:
  35. return Cpp.foo;
  36. }
  37. // ============================================================================
  38. // extern "C" function with C++ special name
  39. // ============================================================================
  40. // --- extern_c_with_special_name.h
  41. struct X {};
  42. extern "C" X operator+(X, X);
  43. // --- fail_todo_import_extern_c_with_special_name.carbon
  44. library "[[@TEST_NAME]]";
  45. import Cpp library "extern_c_with_special_name.h";
  46. fn MyF(a: Cpp.X, b: Cpp.X) -> Cpp.X {
  47. // CHECK:STDERR: fail_todo_import_extern_c_with_special_name.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.AddWith(Cpp.X)` in type `Cpp.X` that does not implement that interface [MissingImplInMemberAccess]
  48. // CHECK:STDERR: return a + b;
  49. // CHECK:STDERR: ^~~~~
  50. // CHECK:STDERR:
  51. return a + b;
  52. }