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 a997161dd6.

Change-Id: I9513b4fdc1fa5247cd67beaf0122b1b1d5494bbf
Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Christian Stenger
2021-11-25 06:59:02 +01:00
parent a997161dd6
commit 857ca05ac3

View File

@@ -147,10 +147,11 @@ CppEditor::CppCodeStyleSettings ClangFormatFile::toCppCodeStyleSettings(
settings.indentFunctionBraces = settings.indentClassBraces; settings.indentFunctionBraces = settings.indentClassBraces;
settings.indentSwitchLabels = style.IndentCaseLabels; settings.indentSwitchLabels = style.IndentCaseLabels;
#if LLVM_VERSION_MAJOR >= 11
settings.indentBlocksRelativeToSwitchLabels = style.IndentCaseBlocks; settings.indentBlocksRelativeToSwitchLabels = style.IndentCaseBlocks;
settings.indentStatementsRelativeToSwitchLabels = style.IndentCaseBlocks; settings.indentStatementsRelativeToSwitchLabels = style.IndentCaseBlocks;
settings.indentControlFlowRelativeToSwitchLabels = style.IndentCaseBlocks; settings.indentControlFlowRelativeToSwitchLabels = style.IndentCaseBlocks;
#endif
if (style.DerivePointerAlignment if (style.DerivePointerAlignment
&& ClangFormatSettings::instance().formatCodeInsteadOfIndent()) { && ClangFormatSettings::instance().formatCodeInsteadOfIndent()) {
settings.bindStarToIdentifier = style.PointerAlignment == FormatStyle::PAS_Right; 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.BreakBeforeBraces = FormatStyle::BS_Whitesmiths;
m_style.IndentCaseLabels = settings.indentSwitchLabels; m_style.IndentCaseLabels = settings.indentSwitchLabels;
#if LLVM_VERSION_MAJOR >= 11
m_style.IndentCaseBlocks = settings.indentBlocksRelativeToSwitchLabels m_style.IndentCaseBlocks = settings.indentBlocksRelativeToSwitchLabels
|| settings.indentStatementsRelativeToSwitchLabels || settings.indentStatementsRelativeToSwitchLabels
|| settings.indentControlFlowRelativeToSwitchLabels; || settings.indentControlFlowRelativeToSwitchLabels;
#endif
if (settings.alignAssignments) if (settings.alignAssignments)
m_style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; m_style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
@@ -218,7 +221,9 @@ TextEditor::TabSettings ClangFormatFile::toTabSettings(ProjectExplorer::Project
settings.m_tabSize = style.TabWidth; settings.m_tabSize = style.TabWidth;
switch (style.UseTab) { switch (style.UseTab) {
#if LLVM_VERSION_MAJOR >= 11
case FormatStyle::UT_AlignWithSpaces: case FormatStyle::UT_AlignWithSpaces:
#endif
case FormatStyle::UT_ForIndentation: case FormatStyle::UT_ForIndentation:
case FormatStyle::UT_ForContinuationAndIndentation: case FormatStyle::UT_ForContinuationAndIndentation:
settings.m_tabPolicy = TextEditor::TabSettings::TabPolicy::MixedTabPolicy; settings.m_tabPolicy = TextEditor::TabSettings::TabPolicy::MixedTabPolicy;