[cfe-dev] invalid-token-paste

Shang Yu yusunn at gmail.com
Wed Jul 18 18:35:41 PDT 2012


Hi James, this code is just a simplified example. In fact I
encountered the problem when I'm testing clang against boost. Please
see the attachment.

2012/7/19 James Dennett <james.dennett at gmail.com>:
> On Wed, Jul 18, 2012 at 5:58 PM, Shang Yu <yusunn at gmail.com> wrote:
>> Hi dear all,
>> Look at the following code
>>
>> #include <stdio.h>
>> #define STR(a,b) a##b
>> void test()
>> {
>>         printf("%s\n" , STR("1","2"));
>> }
>
> That's invalid code.  "1""2" is not a valid token.  Fortunately, you
> don't need it to be -- adjacent string literals are implicitly
> concatenated in a later phase of translation.  You could just use
>   #define STR(a,b) a b
> or drop the macro and write
>   printf("%s\n", "1" "2");
>
>> compiled with clang -c test2.cpp will failed with following error:
>> test2.cpp:9:18: error: pasting formed '"1""2"', an invalid preprocessing token
>>       [-Winvalid-token-paste]
>>         printf("%s\n" , STR("1","2"));
>>                         ^
>> test2.cpp:6:19: note: expanded from macro 'STR'
>> #define STR(a,b) a##b
>>                   ^
>> 1 error generated.
>>                   ^
>
> That looks like a good error message to me -- can you suggest any way
> to make it clearer, or point out any problems with it?
>
>> the same code will pass compiled with msvc. Any suggestion ? Many thanks !
>
> I'd suggest filing a bug against MSVC, but it's not all that important
> -- MSVC will likely accept the corrected code, as will all conforming
> compilers.
>
> -- James
-------------- next part --------------
In file included from E:\SRC\CTEST\boost\stats.cpp:3:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/math/distributions.hpp:15:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/math/distributions/bernoull
i.hpp:33:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/math/distributions/detail/c
ommon_error_handling.hpp:12:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/math/policies/error_handlin
g.hpp:18:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/math/policies/policy.hpp:9:

In file included from E:\SRC\LIBS\boost_1_49_0\boost/mpl/list.hpp:36:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/mpl/list/list20.hpp:18:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/mpl/list/list10.hpp:18:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/mpl/list/list0.hpp:19:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/mpl/list/aux_/push_front.hp
p:18:
In file included from E:\SRC\LIBS\boost_1_49_0\boost/mpl/next.hpp:17:
E:\SRC\LIBS\boost_1_49_0\boost/mpl/next_prior.hpp:44:1: error: pasting formed
      'BOOST_PP_TUPLE_ELEM_E_3(', an invalid preprocessing token
      [-Winvalid-token-paste]
BOOST_MPL_AUX_NA_SPEC(1, next)
^
E:\SRC\LIBS\boost_1_49_0\boost/mpl/aux_/na_spec.hpp:161:40: note: expanded from
      macro 'BOOST_MPL_AUX_NA_SPEC'
#define BOOST_MPL_AUX_NA_SPEC(i, name) \
                                       ^
E:\SRC\LIBS\boost_1_49_0\boost/mpl/aux_/na_spec.hpp:154:47: note: expanded from
      macro '\
BOOST_MPL_AUX_NA_SPEC_NO_ETI'
#define BOOST_MPL_AUX_NA_SPEC_NO_ETI(i, name) \
                                              ^
E:\SRC\LIBS\boost_1_49_0\boost/mpl/aux_/na_spec.hpp:65:9: note: expanded from
      macro '\
BOOST_MPL_AUX_NA_SPEC_MAIN'
        BOOST_MPL_PP_NESTED_DEF_PARAMS_TAIL(i, typename T, na) \
        ^
E:\SRC\LIBS\boost_1_49_0\boost/mpl/aux_/preprocessor/def_params_tail.hpp:97:5: n
ote:
      expanded from macro 'BOOST_MPL_PP_NESTED_DEF_PARAMS_TAIL'
    BOOST_MPL_PP_DEF_PARAMS_TAIL_IMPL(i, param, BOOST_PP_IDENTITY(=value)) \
    ^
E:\SRC\LIBS\boost_1_49_0\boost/mpl/aux_/preprocessor/def_params_tail.hpp:83:11:
note:
      expanded from macro 'BOOST_MPL_PP_DEF_PARAMS_TAIL_IMPL'
        , BOOST_MPL_PP_AUX_TAIL_PARAM_FUNC \
          ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/repetition/repeat.hpp:38:60: note:
      expanded from macro 'BOOST_PP_REPEAT_1'
# define BOOST_PP_REPEAT_1(c, m, d) BOOST_PP_REPEAT_1_I(c, m, d)
                                                           ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/repetition/repeat.hpp:43:63: note:
      expanded from macro 'BOOST_PP_REPEAT_1_I'
# define BOOST_PP_REPEAT_1_I(c, m, d) BOOST_PP_REPEAT_1_ ## c(m, d)
                                                              ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/repetition/repeat.hpp:55:56: note:
      expanded from macro 'BOOST_PP_REPEAT_1_4'
# define BOOST_PP_REPEAT_1_4(m, d) BOOST_PP_REPEAT_1_3(m, d) m(2, 3, d)
                                                       ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/repetition/repeat.hpp:54:56: note:
      expanded from macro 'BOOST_PP_REPEAT_1_3'
# define BOOST_PP_REPEAT_1_3(m, d) BOOST_PP_REPEAT_1_2(m, d) m(2, 2, d)
                                                       ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/repetition/repeat.hpp:53:56: note:
      expanded from macro 'BOOST_PP_REPEAT_1_2'
# define BOOST_PP_REPEAT_1_2(m, d) BOOST_PP_REPEAT_1_1(m, d) m(2, 1, d)
                                                       ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/repetition/repeat.hpp:52:36: note:
      expanded from macro 'BOOST_PP_REPEAT_1_1'
# define BOOST_PP_REPEAT_1_1(m, d) m(2, 0, d)
                                   ^
E:\SRC\LIBS\boost_1_49_0\boost/mpl/aux_/preprocessor/def_params_tail.hpp:77:11:
note:
      expanded from macro 'BOOST_MPL_PP_AUX_TAIL_PARAM_FUNC'
        ) BOOST_PP_TUPLE_ELEM(3, 2, op)() \
          ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/tuple/elem.hpp:36:114: note:
      expanded from macro 'BOOST_PP_TUPLE_ELEM'
  ...n), BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM_E_, size), tuple))
         ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/cat.hpp:22:32: note: expanded from
      macro 'BOOST_PP_CAT'
#    define BOOST_PP_CAT(a, b) BOOST_PP_CAT_I(a, b)
                               ^
E:\SRC\LIBS\boost_1_49_0\boost/preprocessor/cat.hpp:31:55: note: expanded from
      macro 'BOOST_PP_CAT_I'
#    define BOOST_PP_CAT_I(a, b) BOOST_PP_CAT_II(~, a ## b)
                                                      ^


More information about the cfe-dev mailing list