mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:50:13 +01:00
Fix a bunch of cases where we use the same external name to mean multiple different things in the same test. We've historically gotten away with this, but under `--share-cpp-ast`, it becomes an error, at least if the entity is either defined in, or used from, C++ code. Assisted-by: Gemini via Antigravity (original change) and Claude Code (suggested edits in review) --------- Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
101 lines
2.2 KiB
Plaintext
101 lines
2.2 KiB
Plaintext
// 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/namespace/roundtrip.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/namespace/roundtrip.carbon
|
|
|
|
// --- carbon_to_cpp_to_carbon.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
namespace N;
|
|
|
|
inline Cpp '''
|
|
namespace M = Carbon::N;
|
|
''';
|
|
|
|
class C {}
|
|
|
|
fn N.F(c: C);
|
|
|
|
fn G(c: C) {
|
|
Cpp.M.F(c);
|
|
}
|
|
|
|
// --- cpp_to_carbon_to_cpp.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
inline Cpp '''
|
|
namespace N {}
|
|
''';
|
|
|
|
alias M = Cpp.N;
|
|
|
|
inline Cpp '''
|
|
namespace N { void F(); }
|
|
|
|
static_assert(&N::F == &Carbon::M::F);
|
|
''';
|
|
|
|
// --- cpp_carbon.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
fn F();
|
|
|
|
fn G() {
|
|
// TODO: Should we disallow this?
|
|
Cpp.Carbon.F();
|
|
}
|
|
|
|
// --- fail_carbon_cpp.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
inline Cpp '''
|
|
void F();
|
|
|
|
void G() {
|
|
// This is not found because it looks for the identifier `Cpp`, not the keyword `Cpp`.
|
|
// CHECK:STDERR: fail_carbon_cpp.carbon:[[@LINE+4]]:11: error: no member named 'Cpp' in namespace 'Carbon' [CppInteropParseError]
|
|
// CHECK:STDERR: 14 | Carbon::Cpp::F();
|
|
// CHECK:STDERR: | ~~~~~~~~^
|
|
// CHECK:STDERR:
|
|
Carbon::Cpp::F();
|
|
}
|
|
''';
|
|
|
|
// --- fail_carbon_raw_cpp.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
alias r#Cpp = Cpp;
|
|
|
|
inline Cpp '''
|
|
void FRaw();
|
|
|
|
void GRaw() {
|
|
// CHECK:STDERR: fail_carbon_raw_cpp.carbon:[[@LINE+8]]:16: error: semantics TODO: `interop with translation unit decl` [SemanticsTodo]
|
|
// CHECK:STDERR: Carbon::Cpp::FRaw();
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_carbon_raw_cpp.carbon:[[@LINE+4]]:11: error: no member named 'Cpp' in namespace 'Carbon' [CppInteropParseError]
|
|
// CHECK:STDERR: 19 | Carbon::Cpp::FRaw();
|
|
// CHECK:STDERR: | ~~~~~~~~^
|
|
// CHECK:STDERR:
|
|
Carbon::Cpp::FRaw();
|
|
}
|
|
''';
|