diff options
author | David Blaikie <dblaikie@gmail.com> | 2011-10-13 06:08:43 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2011-10-13 06:08:43 +0000 |
commit | 13f8daf70637f8f295134ac8e089dd7721e09085 (patch) | |
tree | 18c0ee01b4b7a86dd5b19a18f8451f08a82363b0 /lib/Parse/ParseDeclCXX.cpp | |
parent | dac6cec94c23ba7c9021590a88878768abde4f2e (diff) |
Fix crash-on-invalid, improve error recovery, and test coverage for missing colon after access specifiers in C++
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141852 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseDeclCXX.cpp')
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 51cdf6b64e..decb7f9ec5 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -2135,12 +2135,23 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, // Current token is a C++ access specifier. CurAS = AS; SourceLocation ASLoc = Tok.getLocation(); + unsigned TokLength = Tok.getLength(); ConsumeToken(); - if (Tok.is(tok::colon)) - Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); - else - Diag(Tok, diag::err_expected_colon); - ConsumeToken(); + SourceLocation EndLoc; + if (Tok.is(tok::colon)) { + EndLoc = Tok.getLocation(); + ConsumeToken(); + } else if (Tok.is(tok::semi)) { + EndLoc = Tok.getLocation(); + ConsumeToken(); + Diag(EndLoc, diag::err_expected_colon) + << FixItHint::CreateReplacement(EndLoc, ":"); + } else { + EndLoc = ASLoc.getLocWithOffset(TokLength); + Diag(EndLoc, diag::err_expected_colon) + << FixItHint::CreateInsertion(EndLoc, ":"); + } + Actions.ActOnAccessSpecifier(AS, ASLoc, EndLoc); continue; } |