Files
carbon-lang/toolchain/check/testdata/interop/cpp/class/export/static.carbon
T
Richard SmithandChandler Carruth c588eadb57 Rename and rearrange entities in tests to avoid name reuse (#7656)
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>
2026-08-21 01:36:40 +00:00

47 lines
1.5 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/int.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/static.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/export/static.carbon
// --- static.carbon
library "[[@TEST_NAME]]";
import Cpp;
class PublicClass {
static var x: i32 = 123;
}
inline Cpp '''
int PublicStatic() {
return Carbon::PublicClass::x;
}
''';
// --- fail_static_private.carbon
library "[[@TEST_NAME]]";
import Cpp;
class PrivateClass {
private static var x: i32 = 123;
}
inline Cpp '''
int PrivateStatic() {
// CHECK:STDERR: fail_static_private.carbon:[[@LINE+7]]:32: error: 'x' is a private member of 'Carbon::PrivateClass' [CppInteropParseError]
// CHECK:STDERR: 17 | return Carbon::PrivateClass::x;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_static_private.carbon:[[@LINE-8]]:23: note: implicitly declared private here [CppInteropParseNote]
// CHECK:STDERR: 5 | private static var x: i32 = 123;
// CHECK:STDERR: | ^
// CHECK:STDERR:
return Carbon::PrivateClass::x;
}
''';