mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 15:55:48 +01:00
When a Carbon virtual function overrides a C++ virtual function, we need to export it with the C++ signature in order for it to work as an override. Instead of mapping the C++ signature into Carbon and then back again, use the original C++ signature from the base class as the signature exported to C++. Also add documentation explaining how we use thunks in C++ interop, including in this new virtual function handling logic.
33 lines
907 B
Plaintext
33 lines
907 B
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/destroy.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/override.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/export/override.carbon
|
|
|
|
// --- const_ref_param.carbon
|
|
library "[[@TEST_NAME]]";
|
|
import Cpp;
|
|
|
|
inline Cpp '''
|
|
struct X {};
|
|
|
|
struct A {
|
|
virtual void f(const X& x) = 0;
|
|
};
|
|
''';
|
|
|
|
class B {
|
|
extend base: Cpp.A;
|
|
override fn f(unused self, unused x: Cpp.X) {}
|
|
}
|
|
|
|
inline Cpp '''
|
|
Carbon::B b;
|
|
''';
|