CppTools: Fix formatting for lambdas with trailing return type

After the arrow, the state is still the same, as now a type is expected.
Only after the opening brace does the actual function start.

Fixes: QTCREATORBUG-18497
Change-Id: I7bf18fbd6907d36f8869af3a78ad617cf0ee9dbb
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-07-30 17:34:36 +02:00
parent 537e2e23ff
commit 3f9427200b
2 changed files with 20 additions and 1 deletions

View File

@@ -127,6 +127,7 @@ private Q_SLOTS:
void strings();
void initializerWithinFunctionArg();
void shiftWithinInitializer();
void lambdaWithReturnType();
};
struct Line {
@@ -2196,6 +2197,18 @@ void tst_CodeFormatter::shiftWithinInitializer()
checkIndent(data);
}
void tst_CodeFormatter::lambdaWithReturnType()
{
QList<Line> data;
data << Line("int main() {")
<< Line(" hello([]() -> void {")
<< Line(" cout << \"world\";") // OK, same indentation/padding as above.
<< Line(" });")
<< Line("}")
;
checkIndent(data);
}
QTEST_MAIN(tst_CodeFormatter)
#include "tst_codeformatter.moc"