[cfe-commits] r134588 - in /cfe/trunk: lib/Lex/TokenLexer.cpp test/Preprocessor/macro_paste_hashhash.c

Argyrios Kyrtzidis kyrtzidis at apple.com
Thu Jul 7 10:45:02 PDT 2011


On Jul 7, 2011, at 9:53 AM, Chris Lattner wrote:

> 
> On Jul 6, 2011, at 8:40 PM, Argyrios Kyrtzidis wrote:
> 
>> Author: akirtzidis
>> Date: Wed Jul  6 22:40:37 2011
>> New Revision: 134588
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=134588&view=rev
>> Log:
>> When expanding macro arguments, treat '##' coming from an argument as a normal token.
>> 
>> e.g.
>> 
>> #define M(x) A x B
>> M(##) // should expand to 'A ## B', not 'AB'
> 
> Thanks for fixing this Argyrios, one comment though:
> 
>>    // Otherwise, this is a use of the argument.  Find out if there is a paste
>>    // (##) operator before or after the argument.
>>    bool PasteBefore =
>> -      !ResultToks.empty() && ResultToks.back().is(tok::hashhash);
>> +      !ResultToks.empty() && ResultToks.back().is(tok::hashhash) &&
>> +      // If the '##' came from expanding an argument,treat it as a normal token.
>> +      SM.isBeforeInSourceLocationOffset(ResultToks.back().getLocation(),
>> +                                        MacroStartSLocOffset);
> 
> This really shouldn't be using SM.isBeforeInSourceLocationOffset.  The way we handle hashhash elsewhere is to turn it into tok::other when it shouldn't cause token pasting.  For example:
> 
>      // Turn ## into 'unknown' to avoid # ## # from looking like a paste
>      // operator.
>      if (Result.is(tok::hashhash))
>        Result.setKind(tok::unknown);
> 
> Can you rework this to have the argument expansion logic strip tok::hashhash's from arguments instead of using the SM.isBeforeInSourceLocationOffset query?

Are you sure ? If we keep tok::hashhash we will be able to have the parser provide an error like gcc's diagnostic "error: stray ‘##’ in program".





More information about the cfe-commits mailing list