Commit 27026af2 authored by Christian Kamm's avatar Christian Kamm
Browse files

C++ indenter: Fix indent of block statements in substatement blocks.

Task-number: QTCREATORBUG-1919
parent 63f7abb0
...@@ -1227,6 +1227,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i ...@@ -1227,6 +1227,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
*indentDepth += m_indentSize; *indentDepth += m_indentSize;
} else if (topState.type != defun_open } else if (topState.type != defun_open
&& topState.type != block_open && topState.type != block_open
&& topState.type != substatement_open
&& !topWasMaybeElse) { && !topWasMaybeElse) {
*indentDepth = topState.savedIndentDepth; *indentDepth = topState.savedIndentDepth;
} }
......
...@@ -45,6 +45,7 @@ private Q_SLOTS: ...@@ -45,6 +45,7 @@ private Q_SLOTS:
void singleLineEnum(); void singleLineEnum();
void functionReturnType(); void functionReturnType();
void streamOp(); void streamOp();
void blockStmtInIf();
}; };
struct Line { struct Line {
...@@ -817,6 +818,23 @@ void tst_CodeFormatter::streamOp() ...@@ -817,6 +818,23 @@ void tst_CodeFormatter::streamOp()
checkIndent(data); checkIndent(data);
} }
void tst_CodeFormatter::blockStmtInIf()
{
QList<Line> data;
data
<< Line("void foo () {")
<< Line(" if (a) {")
<< Line(" {")
<< Line(" foo;")
<< Line(" }")
<< Line(" } else {")
<< Line(" {")
<< Line(" foo;")
<< Line(" }")
;
checkIndent(data);
}
QTEST_APPLESS_MAIN(tst_CodeFormatter) QTEST_APPLESS_MAIN(tst_CodeFormatter)
#include "tst_codeformatter.moc" #include "tst_codeformatter.moc"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment