Skip to content

Wrong token pasting/concatenation when token contains spaces #124

@versat

Description

@versat

Stumbled over this issue when i added a define for the Qt macro Q_D(), see Cppcheck ticket https://trac.cppcheck.net/ticket/8479.
For this C code:

#define CONCAT(tok) tok##suffix

CONCAT(Test);
CONCAT(const Test);

gcc outputs:

$ gcc -E token_pasting_with_space.c
# 1 "token_pasting_with_space.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "token_pasting_with_space.c"


Testsuffix;
const Testsuffix;

simplecpp outputs:

$ ./simplecpp token_pasting_with_space.c


Testsuffix ;
constTestsuffix ;

The space between "const" and "Test" is removed.
Not sure what the standard says about such a case but since Qt and gcc are widely used i guess it should work like Qt expects it and gcc handles it to not break things.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions