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 | eba32c22292ba1d64bd6b7c2c33c9822b0694faa (patch) | |
| tree | e74073b02f1e73b902a557df63eacf66766c9141 | |
| parent | d3043965b9ebaecc4dd60c5dbd1049982adc2520 (diff) | |
| download | bcm5719-llvm-eba32c22292ba1d64bd6b7c2c33c9822b0694faa.tar.gz bcm5719-llvm-eba32c22292ba1d64bd6b7c2c33c9822b0694faa.zip | |
Fix crash-on-invalid, improve error recovery, and test coverage for missing colon after access specifiers in C++
llvm-svn: 141852
| -rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 21 | ||||
| -rw-r--r-- | clang/test/Parser/cxx-class.cpp | 17 |
2 files changed, 33 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 51cdf6b64ec..decb7f9ec5f 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/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; } diff --git a/clang/test/Parser/cxx-class.cpp b/clang/test/Parser/cxx-class.cpp index f863bd198e5..1c0d862b309 100644 --- a/clang/test/Parser/cxx-class.cpp +++ b/clang/test/Parser/cxx-class.cpp @@ -40,3 +40,20 @@ typedef union { } y; } bug3177; +// check that we don't consume the token after the access specifier +// when it's not a colon +class D { +public // expected-error{{expected ':'}} + int i; +}; + +// consume the token after the access specifier if it's a semicolon +// that was meant to be a colon +class E { +public; // expected-error{{expected ':'}} + int i; +}; + +// PR11109 must appear at the end of the source file +class pr11109r3 { // expected-note{{to match this '{'}} + public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}} |

