CppEditor: Fix indentation of function call arguments

... following an argument with an array subscript operator.

Fixes: QTCREATORBUG-29225
Change-Id: Iba38043d94be718efee30ce50f5b55aac4ba6ecd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2024-02-26 15:13:28 +01:00
parent 3f692e2f17
commit e43fde322e
2 changed files with 15 additions and 1 deletions

View File

@@ -204,7 +204,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case T_IDENTIFIER: // '&', id, 'this' are allowed both in the capture list and subscribtion case T_IDENTIFIER: // '&', id, 'this' are allowed both in the capture list and subscribtion
case T_AMPER: case T_AMPER:
case T_THIS: break; case T_THIS: break;
default: leave(); leave(); tryExpression(m_currentState.at(m_currentState.size() - 1).type == declaration_start); break; default: tryExpression(m_currentState.at(m_currentState.size() - 2).type == declaration_start); break;
// any other symbol allowed only in subscribtion operator // any other symbol allowed only in subscribtion operator
} break; } break;

View File

@@ -107,6 +107,7 @@ private Q_SLOTS:
void shiftWithinInitializer(); void shiftWithinInitializer();
void lambdaWithReturnType(); void lambdaWithReturnType();
void structuredBinding(); void structuredBinding();
void subscriptOperatorInFunctionCall();
}; };
struct Line { struct Line {
@@ -2199,6 +2200,19 @@ void tst_CodeFormatter::structuredBinding()
checkIndent(data); checkIndent(data);
} }
void tst_CodeFormatter::subscriptOperatorInFunctionCall()
{
QList<Line> data;
data << Line("int main() {")
<< Line(" func(array[0],")
<< Line(" ~ 0);")
<< Line(" func(array[i],")
<< Line(" ~ i);")
<< Line("}")
;
checkIndent(data);
}
QTEST_GUILESS_MAIN(tst_CodeFormatter) QTEST_GUILESS_MAIN(tst_CodeFormatter)
#include "tst_codeformatter.moc" #include "tst_codeformatter.moc"