[cfe-commits] r169738 - in /cfe/trunk: lib/Format/Format.cpp lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp
Alexander Kornienko
alexfh at google.com
Mon Dec 10 08:34:48 PST 2012
Author: alexfh
Date: Mon Dec 10 10:34:48 2012
New Revision: 169738
URL: http://llvm.org/viewvc/llvm-project?rev=169738&view=rev
Log:
Clang-format: error recovery for access specifiers
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D198
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=169738&r1=169737&r2=169738&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Dec 10 10:34:48 2012
@@ -371,8 +371,9 @@
if (Newlines == 0 && Offset != 0)
Newlines = 1;
unsigned Indent = Line.Level * 2;
- if (Token.Tok.is(tok::kw_public) || Token.Tok.is(tok::kw_protected) ||
- Token.Tok.is(tok::kw_private))
+ if ((Token.Tok.is(tok::kw_public) || Token.Tok.is(tok::kw_protected) ||
+ Token.Tok.is(tok::kw_private)) &&
+ static_cast<int>(Indent) + Style.AccessModifierOffset >= 0)
Indent += Style.AccessModifierOffset;
replaceWhitespace(Token, Newlines, Indent);
return Indent;
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=169738&r1=169737&r2=169738&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Dec 10 10:34:48 2012
@@ -311,7 +311,9 @@
void UnwrappedLineParser::parseAccessSpecifier() {
nextToken();
- nextToken();
+ // Otherwise, we don't know what it is, and we'd better keep the next token.
+ if (FormatTok.Tok.is(tok::colon))
+ nextToken();
addUnwrappedLine();
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=169738&r1=169737&r2=169738&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Dec 10 10:34:48 2012
@@ -498,10 +498,26 @@
// Error recovery tests.
//===----------------------------------------------------------------------===//
-//TEST_F(FormatTest, IncorrectDerivedClass) {
-// verifyFormat("public B {\n"
-// "};");
-//}
+TEST_F(FormatTest, IncorrectAccessSpecifier) {
+ verifyFormat("public:");
+ verifyFormat("class A {\n"
+ "public\n"
+ " void f() {\n"
+ " }\n"
+ "};");
+ verifyFormat("public\n"
+ "int qwerty;");
+ verifyFormat("public\n"
+ "B {\n"
+ "};");
+ verifyFormat("public\n"
+ "{\n"
+ "};");
+ verifyFormat("public\n"
+ "B {\n"
+ " int x;\n"
+ "};");
+}
TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
verifyFormat("{");
More information about the cfe-commits
mailing list