Skip to content

Function-like macro not expanded a second time in some cases #231

@dummyunit

Description

@dummyunit

Preprocessing of this code with simplecpp:

#define CAT(a, b) CAT2(a, b)
#define CAT2(a, b) a ## b
#define FOO x
#define BAR() CAT(F, OO)
#define BAZ CAT(B, AR)()
BAZ

produces this result:

CAT ( F , OO )

All mainstream preprocessors (GCC, Clang, MSVC) produce this result (https://godbolt.org/z/9GhhTarE3):

x

It seems that simplecpp decides to not expand CAT a second time during evaluation of BAZ. I don't know if this is correct from the point of view of the standard.

Some additional observations:

  1. If the last line is replaced with CAT(B, AR)() then all preprocessors produce the same result: x.
  2. If BAR() is converted from function-like macro to regular macro:
    #define BAR CAT(F, OO)
    #define BAZ CAT(B, AR)
    then all preprocessors produce the same result: CAT ( F , OO ).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions