[cfe-dev] More thoughts on user defined literals

Chris Lattner clattner at apple.com
Thu Jul 9 09:43:03 PDT 2009


On Jul 8, 2009, at 4:59 PM, Eli Friedman wrote:

> On Wed, Jul 8, 2009 at 4:51 PM,  
> AlisdairM(public)<public at alisdairm.net> wrote:
>> My inexperienced question is - when we move from lex to parse, is  
>> it easy to identify there is no whitespace between the literal  
>> component and the ud-suffix, or should I be trying to take care of  
>> this in the lexing phase?
>
> You can check in the parser with hasLeadingSpace(), but it's probably
> better to handle it in the lexer; it would massively complicate the
> parser to check for a string in every single place that expects an
> identifier.

This is a really dangerous thing to do.  I'd strongly recommend  
returning these as one token in the lexer.  If not, you end up with  
wierdness like this:

#define X ud

"foo"X

(or whatever the syntax is).  Splitting them up will also break token  
pasting and a number of other things in the preprocessor.

-Chris



More information about the cfe-dev mailing list