Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocessor: incorrect expansion with whitespace + paste operator #597

Closed
ehaas opened this issue Dec 6, 2023 · 2 comments · Fixed by #599
Closed

Preprocessor: incorrect expansion with whitespace + paste operator #597

ehaas opened this issue Dec 6, 2023 · 2 comments · Fixed by #599
Labels
bug Something isn't working

Comments

@ehaas
Copy link
Collaborator

ehaas commented Dec 6, 2023

#define CONTINUE(k) DEFER(k##_HOOK)()
#define DEFER(op) op EMPTY
#define EMPTY
#define F_HOOK() F

CONTINUE( F)
CONTINUE(F)

gcc and clang both produce:

F_HOOK ()
F_HOOK ()

aro produces:

 F
F_HOOK ()

The behavior was the same before the hideset change so I don't think it's related to that.

@Vexu Vexu added the bug Something isn't working label Dec 6, 2023
@ehaas
Copy link
Collaborator Author

ehaas commented Dec 6, 2023

Replacing empty object macros with a placemarker token "fixes" this but I'm not sure why the space breaks it in the first place.

@ehaas
Copy link
Collaborator Author

ehaas commented Dec 7, 2023

Smaller example of the paste operator misbehaving:

#define F(X) (X##Y)

F( )

If there is whitespace inside the parentheses, it errors with:

test.c:1:14: error: pasting formed '(Y', an invalid preprocessing token
#define F(X) (X##Y)
             ^

With no whitespace is correctly expands to (Y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants