Skip to content

Commit

Permalink
abort in delete operators that shouldn't be called (#633)
Browse files Browse the repository at this point in the history
* abort in delete operators that shouldn't be called

Section 3.2 of the C++ standard states that destructor definitions
implicitly "use" operator delete functions. Therefore, these operator
delete functions must be defined even if they are never called by
user code explicitly.
http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#261

gcc allows them to remain as empty definitions. However, not all
compilers allow this.

This pull request creates definitions which if ever called, result
in an abort.

* also the one in nan_typedarray_contents
  • Loading branch information
jBarz authored and kkoopa committed Dec 12, 2016
1 parent e768748 commit 0fe3821
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions nan.h
Expand Up @@ -351,7 +351,9 @@ class HandleScope {
HandleScope(const HandleScope &);
void operator=(const HandleScope &);
void *operator new(size_t size);
void operator delete(void *, size_t);
void operator delete(void *, size_t) {
abort();
}
};

class EscapableHandleScope {
Expand Down Expand Up @@ -392,7 +394,9 @@ class EscapableHandleScope {
EscapableHandleScope(const EscapableHandleScope &);
void operator=(const EscapableHandleScope &);
void *operator new(size_t size);
void operator delete(void *, size_t);
void operator delete(void *, size_t) {
abort();
}
};

//=== TryCatch =================================================================
Expand Down
4 changes: 3 additions & 1 deletion nan_typedarray_contents.h
Expand Up @@ -78,7 +78,9 @@ class TypedArrayContents {

//Disable heap allocation
void *operator new(size_t size);
void operator delete(void *, size_t);
void operator delete(void *, size_t) {
abort();
}

size_t length_;
T* data_;
Expand Down

0 comments on commit 0fe3821

Please sign in to comment.