Skip to content

Commit

Permalink
Merge #6257
Browse files Browse the repository at this point in the history
6257: Cmake Tests: Delete operator check for size_t arg r=hkaiser a=SAtacker

- Clang fails to recognize the global delete operator which has 2 arguments the second one being std::size_t
- Reference - https://godbolt.org/z/q1hMrfKjv
- Fixes #6246

Signed-off-by: Shreyas Atre <shreyasatre16@gmail.com>




Co-authored-by: Shreyas Atre <shreyasatre16@gmail.com>
Co-authored-by: Shreyas Atre <61797109+SAtacker@users.noreply.github.com>
  • Loading branch information
3 people committed May 26, 2023
2 parents 5b092fe + 6f044d4 commit d854c09
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
9 changes: 9 additions & 0 deletions cmake/HPX_AddConfigTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ function(hpx_check_for_cxx11_std_shared_ptr_lwg3018)
)
endfunction()

# ##############################################################################
function(hpx_check_for_cxx14_delete_operator_with_size)
add_hpx_config_test(
HPX_WITH_CXX14_DELETE_OPERATOR_WITH_SIZE
SOURCE cmake/tests/cxx_14_delete_operator_with_size.cpp
FILE ${ARGN}
)
endfunction()

# ##############################################################################
function(hpx_check_for_c11_aligned_alloc)
add_hpx_config_test(
Expand Down
4 changes: 4 additions & 0 deletions cmake/HPX_PerformCxxFeatureTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function(hpx_perform_cxx_feature_tests)

hpx_check_for_c11_aligned_alloc(DEFINITIONS HPX_HAVE_C11_ALIGNED_ALLOC)

hpx_check_for_cxx14_delete_operator_with_size(
DEFINITIONS HPX_WITH_CXX14_DELETE_OPERATOR_WITH_SIZE
)

hpx_check_for_cxx17_std_aligned_alloc(
DEFINITIONS HPX_HAVE_CXX17_STD_ALIGNED_ALLOC
)
Expand Down
19 changes: 19 additions & 0 deletions cmake/tests/cxx_14_delete_operator_with_size.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2023 Shreyas Atre
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <cstddef>
#include <memory>

/// clang fails to compile this with libstdc++ even though gcc does fine

int main()
{
using dealloc_fn = void (*)(void*, std::size_t);
dealloc_fn const dealloc = [](void* const p, std::size_t const s) {
::operator delete[](p, s + sizeof(std::size_t) + sizeof(dealloc_fn));
};
(void) dealloc;
}
14 changes: 9 additions & 5 deletions libs/core/type_support/include/hpx/type_support/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,15 @@ namespace hpx {
void* const ptr = ::operator new[](
size + sizeof(std::size_t) + sizeof(dealloc_fn));

dealloc_fn const dealloc = [](void* const p,
std::size_t const s) {
::operator delete[](
p, s + sizeof(std::size_t) + sizeof(dealloc_fn));
};
dealloc_fn const dealloc =
[](void* const p, [[maybe_unused]] std::size_t const s) {
#if defined(HPX_WITH_CXX14_DELETE_OPERATOR_WITH_SIZE)
::operator delete[](
p, s + sizeof(std::size_t) + sizeof(dealloc_fn));
#else
::operator delete[](p);
#endif
};

char* address = static_cast<char*>(ptr);
*reinterpret_cast<std::size_t*>(address) = size;
Expand Down

0 comments on commit d854c09

Please sign in to comment.