Index: clang/docs/ClangFormatStyleOptions.rst =================================================================== --- clang/docs/ClangFormatStyleOptions.rst +++ clang/docs/ClangFormatStyleOptions.rst @@ -3549,6 +3549,19 @@ For example: Q_UNUSED + Cases in switch block can be defined as StatementMacros. The behavior is + the same as 'case' in switch block. + + .. code-block:: c + switch (x) { + FOO: + break; + case 0: + break; + BAR(var): + break; + } + **TabWidth** (``unsigned``) The number of columns used for tab stops. Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2920,6 +2920,8 @@ nextToken(); if (FormatTok->is(tok::l_paren)) parseParens(); + if (FormatTok->is(tok::colon)) + parseLabel(); if (FormatTok->is(tok::semi)) nextToken(); addUnwrappedLine(); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -3496,6 +3496,33 @@ getLLVMStyleWithColumns(11)); } +TEST_F(FormatTest, StatementMacroInSwitchBlock) { + FormatStyle Style = getLLVMStyle(); + Style.StatementMacros.push_back("FOO"); + Style.SpaceBeforeCtorInitializerColon = false; + EXPECT_EQ("switch (x) {\n" + "FOO:\n" + " break;\n" + "case 0:\n" + " break;\n" + "FOO(var):\n" + " break;\n" + "case 1:\n" + " break;\n" + "}", + format("switch (x) {\n" + "FOO:\n" + " break;\n" + "case 0:\n" + " break;\n" + "FOO(var):\n" + " break;\n" + "case 1:\n" + " break;\n" + "}", + Style)); +} + TEST_F(FormatTest, IndentPreprocessorDirectives) { FormatStyle Style = getLLVMStyle(); Style.IndentPPDirectives = FormatStyle::PPDIS_None;