C++ Logo

STD-DISCUSSION

Advanced search

Subject: Clarification of C++ standard re omission of call to replaceable global allocation function
From: José Luis March Cabrelles (joseluis_at_[hidden])
Date: 2019-09-24 10:45:17


Hi,

I am seeking clarification of a sentence added in C++14 (still present
in later versions) in Section 5.3.4 New [expr.new], Paragraph 10:

 Â Â Â Â Â Â Â  "An implementation is allowed to omit a call to a
 Â Â Â Â Â Â Â  replaceable global allocation function (18.6.1.1,
 Â Â Â Â Â Â Â  18.6.1.2)."

C++14 Section 18.6.1.1 Single-object forms [new.delete.single] says:

 Â Â Â Â Â Â Â  void* operator new(std::size_t size); "Replaceable:
 Â Â Â Â Â Â Â  a C++ program may define a function with this
 Â Â Â Â Â Â Â  function signature that displaces the default
 Â Â Â Â Â Â Â  version defined by the C++ standard library."

My question is:

 Â Â Â Â Â Â Â  Is the function that displaces the default version
 Â Â Â Â Â Â Â  also itself called "replaceable"?

If not, a call to the program-defined function cannot be omitted. And if
not, how can a compiler that translates a call in translation unit T1
know whether it is calling the default library function or a program
defined allocation function defined in translation unit T2?

Another relevant section is C++14, Section 3.7.4 Dynamic storage
duration [basic.stc.dynamic], Paragraph 2:

 Â Â Â Â Â Â Â  "The library provides default definitions for the
 Â Â Â Â Â Â Â  global allocation and deallocation functions. Some
 Â Â Â Â Â Â Â  global allocation and deallocation functions are
 Â Â Â Â Â Â Â  replaceable (18.6.1). A C++ program shall provide at
 Â Â Â Â Â Â Â  most one definition of a replaceable allocation or
 Â Â Â Â Â Â Â  deallocation function. Any such function definition
 Â Â Â Â Â Â Â  replaces the default version provided in the library
 Â Â Â Â Â Â Â  (17.6.4.6)."

This wording suggests that the program defined allocation function is
also to be called "replaceable", even though it has to be unique and
that seems to stretch the meaning of the word "replaceable".

The question whether a call to program-defined global allocation
function can be omitted is relevant if the program-defined function
implements side effects other than just allocating memory. While having
such side effects may not be advisable, the standard does not restrict
it. Here is some example code: https://cpp.godbolt.org/z/ft9I_M

See background in N3664
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3664.html)
that explicitly does not target omission for calls to class-specific
memory allocators.

Thanks for your help.

Best Regards,
 Â Â Â Â  José Luis

-- 
José Luis March Cabrelles, PhD
Software Quality Engineer
joseluis_at_[hidden]
Solid Sands B.V.
Mobile: +31 683 97 23 63
Office: +31 202 44 01 99
www.solidsands.com
SuperTest: the industry standard for C and C++ compiler testing!

STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups