C++ Logo

std-discussion

Advanced search

Are new and delete allowed to be defined as macros in C++17?

From: Julian Waters <tanksherman27_at_[hidden]>
Date: Sun, 14 Sep 2025 00:39:40 +0800
Hi all,

In C++17, new and delete are listed under preprocessing-op-or-punc,
meaning unlike other keywords, it seems that the Standard mandates
that the preprocessor consider these character sequences as
operators/punctuators rather than preprocessor identifiers. Under this
assumption, since the first preprocessing token that appears after
#define and #undef must be an identifier and not an operator or
punctuator, this implies that new and delete cannot be defined as
macros nor undefined via #undef, yet all the big 3 C++ compilers still
seem to allow new or delete to be defined and undefined via the
corresponding directives. Is there wording in the Standard somewhere
that clarifies this or are the big 3 compilers non conforming to the
Standard?

Apologies if this is not the right list to discuss this issue. I could
not find any other list that was meant for discussion about the C++
Standard besides this one.

best regards,
Julian

Received on 2025-09-13 16:40:21