Skip to content

CWG3053 [cpp.replace.general] #undef likely #734

Description

@jakubjelinek

Full name of submitter (unless configured in github; will be published with the issue): Jakub Jelinek

Reference (section label): cpp.replace.general

Link to reflector thread (if any):

Issue description:
Admittedly older issue, but more important with P2843R3
https://eel.is/c++draft/cpp.replace.general#9 allows

#define likely(x) x
#define unlikely(a, b) a + b

but does not allow

#undef likely
#undef unlikely

So, code that would want to define likely/unlikely as function-like macro just temporarily, for some part of code, can't then undefine it.
I'm a little bit worried by this not being IFNDR, there is quite a lot of code in the wild which does

#define inline
#define private public

etc. or e.g.

#define inline __inline__ __attribute__((__always_inline__))

clang has -Wkeyword-macro warning, but it has been tweaked shortly after introduction, such that it doesn't diagnose #undef on any keyword identifiers, doesn't diagnose

#define for for
#define inline __inline__
#define while

with rationale that #undef on keywords is not harmful and defining keyword to self or __ prefixed/suffixed or just prefixed versions is common. In GCC I'm trying to implement it without those special cases and just enable it if -pedantic, but still unsure how much code will it break.

Suggested resolution:
At least something like:
names likely and unlikely may be defined as function-like macros or undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions