@@ -106,14 +106,27 @@ class Macro {
106106 for (const Token *tok = valueToken; tok != endToken;) {
107107 if (tok->op == ' #' ) {
108108 tok = tok->next ;
109-
110- TokenList tokenListHash;
111- tok = expandToken (&tokenListHash, loc, tok, macros, expandedmacros1, expandedmacros, parametertokens);
112-
113- std::string s;
114- for (const Token *hashtok = tokenListHash.cbegin (); hashtok; hashtok = hashtok->next )
115- s += hashtok->str ;
116- output->push_back (newMacroToken (' \" ' + s + ' \" ' , loc));
109+ if (tok->op == ' #' ) {
110+ // A##B => AB
111+ Token *A = output->end ();
112+ if (!A)
113+ throw std::runtime_error (" invalid ##" );
114+ tok = expandToken (output, loc, tok->next , macros, expandedmacros1, expandedmacros, parametertokens);
115+ Token *next = A->next ;
116+ if (!next)
117+ throw std::runtime_error (" invalid ##" );
118+ A->str = A->str + A->next ->str ;
119+ A->flags ();
120+ output->deleteToken (A->next );
121+ } else {
122+ // #123 => "123"
123+ TokenList tokenListHash;
124+ tok = expandToken (&tokenListHash, loc, tok, macros, expandedmacros1, expandedmacros, parametertokens);
125+ std::string s;
126+ for (const Token *hashtok = tokenListHash.cbegin (); hashtok; hashtok = hashtok->next )
127+ s += hashtok->str ;
128+ output->push_back (newMacroToken (' \" ' + s + ' \" ' , loc));
129+ }
117130 } else {
118131 tok = expandToken (output, loc, tok, macros, expandedmacros1, expandedmacros, parametertokens);
119132 }
0 commit comments