simplecpp icon indicating copy to clipboard operation
simplecpp copied to clipboard

Wrong testcase for ##

Open keinflue opened this issue 4 years ago • 4 comments

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~~

## only has special meaning inside a macro's replacement list. So it should remain unchanged here:

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

// Old, incorrect! Only for reference!
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__.~~

keinflue avatar May 12 '21 16:05 keinflue

:+1:

danmar avatar May 13 '21 05:05 danmar