summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp5
-rw-r--r--clang/unittests/Format/FormatTest.cpp12
2 files changed, 12 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 7e8efad26b6..3df7839b79b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -841,9 +841,8 @@ void UnwrappedLineParser::parseStructuralElement() {
if (Line->Tokens.size() == 1 &&
// JS doesn't have macros, and within classes colons indicate fields,
// not labels.
- (Style.Language != FormatStyle::LK_JavaScript ||
- !Line->MustBeDeclaration)) {
- if (FormatTok->Tok.is(tok::colon)) {
+ Style.Language != FormatStyle::LK_JavaScript) {
+ if (FormatTok->Tok.is(tok::colon) && !Line->MustBeDeclaration) {
parseLabel();
return;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 183fa4418be..16062dd40b7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -812,9 +812,11 @@ TEST_F(FormatTest, FormatsLabels) {
" some_more_code();\n"
" }\n"
"}");
- verifyFormat("some_code();\n"
+ verifyFormat("{\n"
+ " some_code();\n"
"test_label:\n"
- "some_other_code();");
+ " some_other_code();\n"
+ "}");
}
//===----------------------------------------------------------------------===//
@@ -2143,6 +2145,12 @@ TEST_F(FormatTest, FormatsBitfields) {
" int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa : 1,\n"
" bbbbbbbbbbbbbbbbbbbbbbbbb;\n"
"};");
+ verifyFormat("struct MyStruct {\n"
+ " uchar data;\n"
+ " uchar : 8;\n"
+ " uchar : 8;\n"
+ " uchar other;\n"
+ "};");
}
TEST_F(FormatTest, FormatsNamespaces) {
OpenPOWER on IntegriCloud