From c6ce36d56cd5e874e60c3ba8a36cc77c307df718 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Sat, 18 Aug 2018 09:09:15 +0100 Subject: Add placement new operator --- cores/arduino/new.cpp | 4 ++++ cores/arduino/new.h | 1 + 2 files changed, 5 insertions(+) diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp index cf6f89c..bfb219d 100644 --- a/cores/arduino/new.cpp +++ b/cores/arduino/new.cpp @@ -26,6 +26,10 @@ void *operator new[](size_t size) { return malloc(size); } +void * operator new(size_t size, void * ptr) { + return ptr; +} + void operator delete(void * ptr) { free(ptr); } diff --git a/cores/arduino/new.h b/cores/arduino/new.h index 6e1b68f..7690911 100644 --- a/cores/arduino/new.h +++ b/cores/arduino/new.h @@ -23,6 +23,7 @@ void * operator new(size_t size); void * operator new[](size_t size); +void * operator new(size_t size, void * ptr); void operator delete(void * ptr); void operator delete[](void * ptr); -- cgit v1.2.3-18-g5258 From b410611ffcdcb822d69c828f01dd6216c1ef3348 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Sat, 18 Aug 2018 09:27:06 +0100 Subject: Prevent possible compiler warning Casting to void is a well known trick for prevening 'unused parameter' warnings. --- cores/arduino/new.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp index bfb219d..86a1fa5 100644 --- a/cores/arduino/new.cpp +++ b/cores/arduino/new.cpp @@ -27,6 +27,7 @@ void *operator new[](size_t size) { } void * operator new(size_t size, void * ptr) { + (void)size; return ptr; } -- cgit v1.2.3-18-g5258 From 6a717473175cc7d900fe67bc071f7e7c72f01e29 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Fri, 26 Oct 2018 19:34:34 +0100 Subject: Add noexcept specifier to placement new operator The standard mandates that placement new should be have a noexcept specifier. --- cores/arduino/new.cpp | 2 +- cores/arduino/new.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp index 86a1fa5..fc30cf8 100644 --- a/cores/arduino/new.cpp +++ b/cores/arduino/new.cpp @@ -26,7 +26,7 @@ void *operator new[](size_t size) { return malloc(size); } -void * operator new(size_t size, void * ptr) { +void * operator new(size_t size, void * ptr) noexcept { (void)size; return ptr; } diff --git a/cores/arduino/new.h b/cores/arduino/new.h index 7690911..763f5cc 100644 --- a/cores/arduino/new.h +++ b/cores/arduino/new.h @@ -23,7 +23,7 @@ void * operator new(size_t size); void * operator new[](size_t size); -void * operator new(size_t size, void * ptr); +void * operator new(size_t size, void * ptr) noexcept; void operator delete(void * ptr); void operator delete[](void * ptr); -- cgit v1.2.3-18-g5258