Skip to content

Commit 6b5eb85

Browse files
committed
More correctly detect the presence of aligned/sized new/delete.
This fixes a problem with the interaction of Clang and libstdc++'s operator new overloads. Also do some drive-by fixes to make sure everything compiles cleanly with Clang and C++17. Bug 2843412
1 parent aa6f68c commit 6b5eb85

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

testing/scan.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <thrust/scan.h>
33
#include <thrust/functional.h>
44
#include <thrust/iterator/discard_iterator.h>
5+
#include <thrust/iterator/constant_iterator.h>
56
#include <thrust/iterator/retag.h>
67
#include <thrust/device_malloc.h>
78
#include <thrust/device_free.h>

thrust/device_new_allocator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ template<typename T>
139139
inline void deallocate(pointer p, size_type cnt)
140140
{
141141
// use "::operator delete" rather than keyword delete
142+
(void)cnt;
142143
device_delete(p);
143144
} // end deallocate()
144145

thrust/mr/new.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class new_delete_resource THRUST_FINAL : public memory_resource<>
4040
public:
4141
void * do_allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) THRUST_OVERRIDE
4242
{
43-
#if __cplusplus >= 201703L
43+
#if defined(__cpp_aligned_new)
4444
return ::operator new(bytes, std::align_val_t(alignment));
4545
#else
4646
// allocate memory for bytes, plus potential alignment correction,
@@ -61,8 +61,13 @@ class new_delete_resource THRUST_FINAL : public memory_resource<>
6161

6262
void do_deallocate(void * p, std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) THRUST_OVERRIDE
6363
{
64-
#if __cplusplus >= 201703L
64+
#if defined(__cpp_aligned_new)
65+
# if defined(__cpp_sized_deallocation)
6566
::operator delete(p, bytes, std::align_val_t(alignment));
67+
# else
68+
(void)bytes;
69+
::operator delete(p, std::align_val_t(alignment));
70+
# endif
6671
#else
6772
(void)alignment;
6873
char * ptr = static_cast<char *>(p);

0 commit comments

Comments
 (0)