mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 10:51:06 +01:00
Create a placement operator new directly. (#6941)
Instead of injecting code to declare an `operator new`, generate AST for it directly. In order to use this, directly generate a `CXXNewExpr` rather than asking Clang to build one. This is less of a hack, and doesn't visibly leak an `operator new` declaration that inline C++ code or template instantiations might see. It also avoids generating a warning in C++26 and later that the `constexpr` declaration of `operator new` is used but not defined. Assisted-by: Gemini 3.1 Pro via Antigravity
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// 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
|
||||
// EXTRA-ARGS: --clang-arg=--std=c++26
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/function/thunk_cpp26.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/thunk_cpp26.carbon
|
||||
|
||||
// --- thunk_required.h
|
||||
|
||||
auto foo(short a) -> short;
|
||||
|
||||
// --- import_thunk_required.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "thunk_required.h";
|
||||
|
||||
fn F() {
|
||||
// Placement operator new is `constexpr` in C++26. But that shouldn't cause
|
||||
// problems for us because we declare our own operator new.
|
||||
Cpp.foo(1 as i16);
|
||||
}
|
||||
Reference in New Issue
Block a user