[PATCH] Improve error recovery around colon.
Richard Smith
richard at metafoo.co.uk
Thu May 22 16:43:27 PDT 2014
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2706,7 +2706,7 @@
case tok::identifier: {
// In C++, check to see if this is a scope specifier like
foo::bar::, if
// so handle it as such. This is important for ctor parsing.
- if (getLangOpts().CPlusPlus) {
+ if (getLangOpts().CPlusPlus && !DS.hasTypeSpecifier()) {
Please instead swap over this 'if' and the next one.
@@ -4508,8 +4508,10 @@
// Member pointers get special handling, since there's no place for the
// scope spec in the generic path below.
if (getLangOpts().CPlusPlus &&
- (Tok.is(tok::coloncolon) || Tok.is(tok::identifier) ||
- Tok.is(tok::annot_cxxscope))) {
+ (Tok.is(tok::coloncolon) ||
+ (Tok.is(tok::identifier) && (NextToken().is(tok::coloncolon) ||
+ NextToken().is(tok::less))) ||
+ Tok.is(tok::annot_cxxscope))) {
I don't think this is quite sufficient. If we have:
struct A { enum E {}; };
struct B {
static const int N = 3;
A::E : N;
};
... I think we might treat the : as a :: typo. Instead, drop a
ColonProtectionRAII object into this 'if', with a comment saying you're
doing it for bitfields, if you're in a member context.
On Fri, May 9, 2014 at 4:17 AM, Serge Pavlov <sepavloff at gmail.com> wrote:
> Hi Richard,
>
> Could you please review this fix?
> Thank you.
>
> --Serge
>
> Recognize additional cases, when '::' is mistyped as ':' and provide
> descriptive diagnostics for them.
> This is a fix to RP18587 - colons have too much protection in
> member-declarations
>
> http://reviews.llvm.org/D3653
>
> Files:
> lib/Parse/ParseDecl.cpp
> lib/Parse/ParseDeclCXX.cpp
> test/SemaCXX/nested-name-spec.cpp
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140522/a6b3f00c/attachment.html>
More information about the cfe-commits
mailing list