mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:51:03 +01:00
Support round-tripping entities through C++ and Carbon. (#7022)
Use the same C++ -> Carbon map for both interop directions, and when importing an entity from Carbon -> C++, check whether it was originally a C++ entity and if so return the original. Assisted-by: Gemini via Google Antigravity
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/roundtrip.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/roundtrip.carbon
|
||||
|
||||
// --- carbon_to_cpp_to_carbon.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
class C {}
|
||||
|
||||
inline Cpp '''
|
||||
using CAlias = Carbon::C;
|
||||
''';
|
||||
|
||||
fn F(p: C*) {
|
||||
let unused q: Cpp.CAlias* = p;
|
||||
}
|
||||
|
||||
// --- cpp_to_carbon_to_cpp.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
inline Cpp '''
|
||||
class C {};
|
||||
''';
|
||||
|
||||
alias CAlias = Cpp.C;
|
||||
|
||||
inline Cpp '''
|
||||
auto F(C *p) -> Carbon::CAlias* {
|
||||
return p;
|
||||
}
|
||||
''';
|
||||
Reference in New Issue
Block a user