Title
Replacing global operator new
Status
resolved
Section
[new.delete]
Submitter
Stephen Clamage

Created on 2014-02-20.00:00:00 last changed 90 months ago

Messages

Date: 2017-07-16.20:11:05

[ 2016-07, Toronto Thursday night issues processing ]

Resolved by P0003.

Date: 2016-03-08.22:51:25

[ 2016-03, Jacksonville ]

STL: Core changes to remove dynamic exception specs would make this moot
Room: This is on track to be resolved by P0003, or may be moot.

Date: 2014-03-24.22:19:13

Section [new.delete] and subsections shows:

void* operator new(std::size_t size);
void* operator new[](std::size_t size);

That is, without exception-specifications. (Recall that C++03 specified these functions with throw(std::bad_alloc).)

Section [res.on.exception.handling] the end of paragraph 4 says:

Any other functions defined in the C++ standard library that do not have an exception-specification may throw implementation-defined exceptions unless otherwise specified. An implementation may strengthen this implicit exception-specification by adding an explicit one.

For example, an implementation could provide C++03-compatible declarations of operator new.

Programmers are allowed to replace these operator new functions. But how can you write the definition of these functions when the exception specification can vary among implementations? For example, the declarations

void* operator new(std::size_t size) throw(std::bad_alloc);
void* operator new(std::size_t size);

are not compatible.

From what I have been able to determine, gcc has a hack for the special case of operator new to ignore the differences in (at least) the two cases I show above. But can users expect all compilers to quietly ignore the incompatibility?

The blanket permission to add any explicit exception specification could cause a problem for any user-overridable function. Different implementations could provide incompatible specifications, making portable code impossible to write.

History
Date User Action Args
2017-07-16 20:11:05adminsetmessages: + msg9414
2017-07-16 20:11:05adminsetstatus: open -> resolved
2016-03-08 22:51:25adminsetmessages: + msg8023
2016-03-08 22:51:25adminsetstatus: new -> open
2014-02-20 00:00:00admincreate