mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 13:48:31 +00:00
When exporting `X` from Carbon package `Foo`, expose it to C++ with fully-qualified name `Carbon::Foo::X`, not simply `Carbon::X`. This ensures that C++ mangled names properly distinguish between same-named Carbon entities in different packages. Name *lookup* into `Carbon::` still uses the same rules as before: it finds what a `package.` lookup would find in Carbon. So `X` is named from C++ as `Carbon::X` still, and a lookup for `Carbon::Foo` fails, even though `X`'s "true name" is now `Carbon::Foo::X`. Assisted-by: Gemini via Antigravity
95 lines
2.6 KiB
Plaintext
95 lines
2.6 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/primitives.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/export/class.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/export/class.carbon
|
|
|
|
// --- static_members.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
class StaticMembers {
|
|
fn F() {}
|
|
}
|
|
|
|
inline Cpp '''
|
|
void CallStaticMember() {
|
|
Carbon::StaticMembers::F();
|
|
}
|
|
''';
|
|
|
|
// --- nested.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
class OuterA {
|
|
class InnerB {
|
|
class NestedC {
|
|
}
|
|
}
|
|
}
|
|
|
|
inline Cpp '''
|
|
void TestNested() {
|
|
Carbon::OuterA::InnerB::NestedC *nested_p = nullptr;
|
|
}
|
|
''';
|
|
|
|
// --- incomplete.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
class IncompleteA;
|
|
|
|
inline Cpp '''
|
|
Carbon::IncompleteA *incomplete_p = nullptr;
|
|
''';
|
|
|
|
// --- fail_incomplete_concrete.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
// CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+2]]:1-26: error: class was forward declared here [ClassForwardDeclaredHere]
|
|
// CHECK:STDERR:
|
|
class IncompleteConcreteA;
|
|
|
|
inline Cpp '''
|
|
// CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+3]]:29: error: variable has incomplete type 'Carbon::IncompleteConcreteA' (aka 'Carbon::Main::IncompleteConcreteA') [CppInteropParseError]
|
|
// CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE-4]]:26: note: forward declaration of 'Carbon::Main::IncompleteConcreteA' [CppInteropParseNote]
|
|
// CHECK:STDERR:
|
|
Carbon::IncompleteConcreteA incomplete_concrete_a;
|
|
''';
|
|
|
|
// --- fail_todo_monomorphization_failure.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp;
|
|
|
|
// CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+2]]:1-17: error: semantics TODO: `binding maps to a non-type template parameter` [SemanticsTodo]
|
|
// CHECK:STDERR:
|
|
class B(N: i32) {
|
|
var a: array(i8, N);
|
|
}
|
|
|
|
// TODO: Once we allow this, we should produce an "invalid array bound" error
|
|
// during monomorphization triggered by the C++ code.
|
|
alias T = B(-1);
|
|
|
|
inline Cpp '''
|
|
// CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+4]]:1: error: semantics TODO: `interop with unsupported type` [SemanticsTodo]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+2]]:9: error: no type named 'T' in namespace 'Carbon' [CppInteropParseError]
|
|
// CHECK:STDERR:
|
|
Carbon::T t;
|
|
''';
|