simplecpp
simplecpp copied to clipboard
Wrong testcase for ##
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__.~~
:+1: