C++ Logo

std-discussion

Advanced search

Clarification of C++ standard re omission of call to replaceable global allocation function

From: José Luis March Cabrelles <joseluis_at_[hidden]>
Date: Tue, 24 Sep 2019 17:45:17 +0200
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!

Received on 2019-09-24 10:47:31