Skip to content

Commit 35aeeb6

Browse files
committed
[libc++] Provide sized deallocation declarations even when the compiler doesn't support sized deallocation
After ef804d8, we stopped providing the declaration of sized deallocation functions unless the compiler provides support for the language feature. In reality, we can still provide the declarations of global operator delete for users who want to call these operators directly without going through the compiler rewrite.
1 parent c7c7eab commit 35aeeb6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

libcxx/include/__new/global_new_delete.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# define _THROW_BAD_ALLOC
2626
#endif
2727

28-
#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
28+
#if _LIBCPP_STD_VER >= 14
2929
# define _LIBCPP_HAS_SIZED_DEALLOCATION 1
3030
#else
3131
# define _LIBCPP_HAS_SIZED_DEALLOCATION 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Ensure that libc++ still provides the declaration of sized operator delete even
10+
// when sized deallocation support is disabled at the language level, since it should
11+
// still be valid to call these operators explicitly (as opposed to via a compiler
12+
// rewrite of a delete expression).
13+
14+
// UNSUPPORTED: c++03, c++11
15+
16+
// ADDITIONAL_COMPILE_FLAGS: -fno-sized-deallocation
17+
18+
// Sized deallocation support was introduced in LLVM 11
19+
// XFAIL: using-built-library-before-llvm-11
20+
21+
#include <new>
22+
23+
int main(int, char**) {
24+
void* p = ::operator new(10);
25+
::operator delete(p, 10);
26+
return 0;
27+
}

0 commit comments

Comments
 (0)