diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 3fea52b9f8af86c177259f9fc114a0c50307cc4a..902cbb8f44c33352908615d1f65376afe757d7ee 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -392,7 +392,8 @@ private: Tok->Type = TT_RangeBasedForLoopColon; } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) { Tok->Type = TT_BitFieldColon; - } else if (Contexts.size() == 1 && Line.First->isNot(tok::kw_enum)) { + } else if (Contexts.size() == 1 && + !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) { Tok->Type = TT_InheritanceColon; } else if (Contexts.back().ContextKind == tok::l_paren) { Tok->Type = TT_InlineASMColon; @@ -1655,11 +1656,11 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, return Style.BreakBeforeTernaryOperators; if (Left.Type == TT_ConditionalExpr || Left.is(tok::question)) return !Style.BreakBeforeTernaryOperators; - if (Right.is(tok::colon) && - (Right.Type == TT_DictLiteral || Right.Type == TT_ObjCMethodExpr)) - return false; if (Right.Type == TT_InheritanceColon) return true; + if (Right.is(tok::colon) && (Right.Type != TT_CtorInitializerColon && + Right.Type != TT_InlineASMColon)) + return false; if (Left.is(tok::colon) && (Left.Type == TT_DictLiteral || Left.Type == TT_ObjCMethodExpr)) return true; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 8ad59cd93e197ca0aa6acdc5dec7ce82aa196ef1..712af88329eece3a2bd4209b306b94f142b521d7 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -683,6 +683,13 @@ TEST_F(FormatTest, FormatsSwitchStatement) { "case (b):\n" " return;\n" "}"); + + verifyFormat("switch (a) {\n" + "case some_namespace::\n" + " some_constant:\n" + " return;\n" + "}", + getLLVMStyleWithColumns(34)); } TEST_F(FormatTest, CaseRanges) {