Hi All,
A commit earlier this year, r325630, changed the behavior of the following program under –O1:
Hi All,
A commit earlier this year, r325630, changed the behavior of the following program under –O1:
(remembering to cc the list this time)
More generally, a (non-placement) new-expression is not required to call any ‘operator new’ in particular to get its storage. It’s permitted to do so, but it’s also permitted to get storage from another place (such as the heap) or combine multiple allocations into a single operator new call, so long as all the relevant side-conditions are satisfied. (Calls to ‘operator new’ from new-expressions are considered non-observable behavior in some sense.)
To be precise, this rule applies to new-expressions that directly use one
of the “replaceable global allocation functions”, which both includes some
placement forms (e.g. new (std::nothrow) double[10]
) and excludes some
non-placement forms (e.g. new MyClass
where MyClass
declares an
operator new
).
John.
Thanks Hal and Richard,
Ø The implementation is allowed to elide those side effects, and the standard was clarified in recent years to reflect this explicitly.
That settles it.
Thanks.
Sunil Srivastava