Title
Block-scope declarations of allocator functions
Status
nad
Section
7.6.2.8 [expr.new]
Submitter
John Spicer

Created on 2004-07-12.00:00:00 last changed 9 months ago

Messages

Date: 2023-07-02.20:55:11

Rationale

The wording correctly reflects the intent; block-scope allocation functions are not found by the special lookup in a new-expression.

Date: 2004-10-15.00:00:00

Notes from October 2004 meeting:

The CWG agreed that the block-scope declaration should not be found by the lookup in a new-expression. It would, however, be found by ordinary lookup if the allocation function were invoked explicitly.

Date: 2004-07-12.00:00:00

Looking up operator new in a new-expression uses a different mechanism from ordinary lookup. According to 7.6.2.8 [expr.new] paragraph 9,

If the new-expression begins with a unary :: operator, the allocation function's name is looked up in the global scope. Otherwise, if the allocated type is a class type T or array thereof, the allocation function's name is looked up in the scope of T. If this lookup fails to find the name, or if the allocated type is not a class type, the allocation function's name is looked up in the global scope.

Note in particular that the scope in which the new-expression occurs is not considered. For example,

    void f() {
        void* operator new(std::size_t, void*);
        int* i = new int;    // okay?
    }

In this example, the implicit reference to operator new(std::size_t) finds the global declaration, even though the block-scope declaration of operator new with a different signature would hide it from an ordinary reference.

This seems strange; either the block-scope declaration should be ill-formed or it should be found by the lookup.

History
Date User Action Args
2023-07-02 20:55:11adminsetmessages: + msg7352
2023-07-02 20:55:11adminsetstatus: open -> nad
2004-11-07 00:00:00adminsetmessages: + msg1082
2004-07-12 00:00:00admincreate