Skip to content

expandHashHash(): function-like macro not expanded when '(' is not adjacent (PAR-style indirection) #656

Description

@paulafy6

When ## concatenation produces a function-like macro name but the argument list (...) is not immediately adjacent in the replacement text (hidden behind a secondary macro parameter), simplecpp aborts expansion and emits the concatenated token bare.

Reproducer

#define PAR(a, ...) a __VA_ARGS__
#define PREFIX_SCALAR(T, N) T N
#define DISPATCH(kind, ...) PAR(PREFIX_ ## kind, (__VA_ARGS__))
DISPATCH(SCALAR, int, x)

Expected:

int x

Actual:

1:
2:
3:
4: PREFIX_SCALAR ( int , x )

Root cause

expandHashHash() checks only B->next->op == '(' immediately after the ## result. In the PAR pattern, B->next is , (not (), so the function-like expansion is skipped.

Fix

A forward-scan fallback in the appendTokens context (expandResult==false) walks ahead on the same line, skipping , separators and resolving named parameter tokens via expandArg(), until ( is found.

PR attached: #655

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions