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

Wrong testcase for ## #223

Open
keinflue opened this issue May 12, 2021 · 1 comment
Open

Wrong testcase for ## #223

keinflue opened this issue May 12, 2021 · 1 comment

Comments

@keinflue
Copy link
Contributor

keinflue commented May 12, 2021

The following testcase is not correct:

static void hashhash5()
{
    ASSERT_EQUALS("x1", preprocess("x##__LINE__"));
}

Replacement of macros should happen only after ## has been "evaluated". See §6.10.3.1 and §6.10.3.4 of C11 (n1570), so the corrected test case would be

static void hashhash5()
{
    ASSERT_EQUALS("x__LINE__", preprocess("x##__LINE__"));
}

This also applies if the token(s) next to ## are macro parameters and the corresponding macro argument contains expandable macro names (in contrast to the general behavior of expanding the argument first), meaning that e.g.:

#define X(x) x##__LINE__
#define Y(x) X(x)
X(__LINE__) Y(__LINE__)

should preprocess to __LINE____LINE__ 3__LINE__.

@danmar
Copy link
Owner

danmar commented May 13, 2021

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants