[cfe-commits] Patch: Add fix-it for digraph errors involving &quot; <::&quot;

Richard Smith richard at metafoo.co.uk
Mon Apr 4 13:19:03 PDT 2011


On Wed, 30 Mar 2011, Richard Trieu <rtrieu at google.com> wrote:
> Detect when the string "<::" is found in code after a cast or template
> name and is interpreted as "[:" because of the digraph "<:".  When found,
> give an error with a fix-it to add whitespace between the "<" and "::".
> Also, repair the token stream and recover parsing afterwards.

I don't think that this is the right fix. In C++0x, '<::' (not followed by
':' or '>') is lexed as '<' followed by '::' (see [lex.pptoken]p3 bullet
2, or http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1104).
Implementing that rule (for both C++0x and earlier) seems to me like a
better fit, even though it breaks legal-but-pathological C++98 programs
like this:

int a[42];
#define A(n) a<::##:n:>
int b = A(b);

Richard





More information about the cfe-commits mailing list