From 857ca05ac37d43bd5895b8a25a014e93c7570d4a Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 25 Nov 2021 06:59:02 +0100 Subject: [PATCH] ClangFormat: Fix compile for old LLVM Using LLVM10 is minimum supported, but some format style elements have been introduced later, so guard access to members that are not present in LLVM10. Amends a997161dd6e832ff. Change-Id: I9513b4fdc1fa5247cd67beaf0122b1b1d5494bbf Reviewed-by: Artem Sokolovskii Reviewed-by: Christian Kandeler --- src/plugins/clangformat/clangformatfile.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/clangformat/clangformatfile.cpp b/src/plugins/clangformat/clangformatfile.cpp index 44adde76b04..9c3b7c6717e 100644 --- a/src/plugins/clangformat/clangformatfile.cpp +++ b/src/plugins/clangformat/clangformatfile.cpp @@ -147,10 +147,11 @@ CppEditor::CppCodeStyleSettings ClangFormatFile::toCppCodeStyleSettings( settings.indentFunctionBraces = settings.indentClassBraces; settings.indentSwitchLabels = style.IndentCaseLabels; +#if LLVM_VERSION_MAJOR >= 11 settings.indentBlocksRelativeToSwitchLabels = style.IndentCaseBlocks; settings.indentStatementsRelativeToSwitchLabels = style.IndentCaseBlocks; settings.indentControlFlowRelativeToSwitchLabels = style.IndentCaseBlocks; - +#endif if (style.DerivePointerAlignment && ClangFormatSettings::instance().formatCodeInsteadOfIndent()) { settings.bindStarToIdentifier = style.PointerAlignment == FormatStyle::PAS_Right; @@ -178,9 +179,11 @@ void ClangFormatFile::fromCppCodeStyleSettings(const CppEditor::CppCodeStyleSett m_style.BreakBeforeBraces = FormatStyle::BS_Whitesmiths; m_style.IndentCaseLabels = settings.indentSwitchLabels; +#if LLVM_VERSION_MAJOR >= 11 m_style.IndentCaseBlocks = settings.indentBlocksRelativeToSwitchLabels || settings.indentStatementsRelativeToSwitchLabels || settings.indentControlFlowRelativeToSwitchLabels; +#endif if (settings.alignAssignments) m_style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; @@ -218,7 +221,9 @@ TextEditor::TabSettings ClangFormatFile::toTabSettings(ProjectExplorer::Project settings.m_tabSize = style.TabWidth; switch (style.UseTab) { +#if LLVM_VERSION_MAJOR >= 11 case FormatStyle::UT_AlignWithSpaces: +#endif case FormatStyle::UT_ForIndentation: case FormatStyle::UT_ForContinuationAndIndentation: settings.m_tabPolicy = TextEditor::TabSettings::TabPolicy::MixedTabPolicy;