diff --git a/src/shared/indenter/constants.cpp b/src/shared/indenter/constants.cpp index 1998df0945f2d312728a9f9b5633c357ca7daff6..a10b584c8f50308587b65eb81600e9b2344beb9a 100644 --- a/src/shared/indenter/constants.cpp +++ b/src/shared/indenter/constants.cpp @@ -49,7 +49,8 @@ Constants::Constants() : m_iflikeKeyword(QLatin1String("\\b(?:catch|do|for|if|while|foreach)\\b")), m_caseLabel(QLatin1String("^\\s*(?:case\\b(?:[^:]|::)+" "|(?:public|protected|private|signals|Q_SIGNALS|default)(?:\\s+slots|\\s+Q_SLOTS)?\\s*" - "):")) + "):")), + m_templateFunc(QLatin1String("template<.*>")) { m_literal.setMinimal(true); m_inlineCComment.setMinimal(true); @@ -59,4 +60,5 @@ Constants::Constants() : Q_ASSERT(m_braceX.isValid()); Q_ASSERT(m_iflikeKeyword.isValid()); Q_ASSERT(m_caseLabel.isValid()); + Q_ASSERT(m_templateFunc.isValid()); } diff --git a/src/shared/indenter/indenter.h b/src/shared/indenter/indenter.h index 813e4569061625fe71ed8fa426df2a856cec83cc..2ce3dca669c8de3ffafd672a2cb32fde094da1ad 100644 --- a/src/shared/indenter/indenter.h +++ b/src/shared/indenter/indenter.h @@ -54,6 +54,7 @@ struct Constants { QRegExp m_braceX; QRegExp m_iflikeKeyword; QRegExp m_caseLabel; + QRegExp m_templateFunc; }; /* The "linizer" is a group of functions and variables to iterate diff --git a/src/shared/indenter/indenter_impl.h b/src/shared/indenter/indenter_impl.h index 254ba12f1137dae103d28546d50c8cbee642a7ff..7255cfa8c92b212e72b5377e4a0395e8d8177585 100644 --- a/src/shared/indenter/indenter_impl.h +++ b/src/shared/indenter/indenter_impl.h @@ -647,10 +647,11 @@ bool Indenter<Iterator>::isUnfinishedLine() if ( ! m_constants.m_bracesSemicolon.contains(lastCh) && !yyLine->endsWith(m_constants.m_3dots) ) { /* It doesn't end with ';' or similar. If it's neither - "Q_OBJECT" nor "if ( x )", it must be an unfinished line. + "Q_OBJECT" nor "if ( x )" nor is a template function, it must be an unfinished line. */ - unf = ( yyLine->contains(m_constants.m_qobject) == 0 && - !matchBracelessControlStatement() ); + unf = ( !yyLine->contains(m_constants.m_qobject) && + !matchBracelessControlStatement() && + !yyLine->contains(m_constants.m_templateFunc) ); } else if ( lastCh == semicolon ) { if ( lastParen(*yyLine) == openingParenthesis ) { /* diff --git a/src/shared/indenter/test/main.cpp b/src/shared/indenter/test/main.cpp index 17be83165442d189c14fc680486b82f5c85b5cab..d1a30923b4bfe26f1c303622961396a926e99dfc 100644 --- a/src/shared/indenter/test/main.cpp +++ b/src/shared/indenter/test/main.cpp @@ -143,7 +143,7 @@ int format(const QString &fileName) if (p.last().endsWith(colon)) typedIn = colon; - const int indent = Indenter::instance().indentForBottomLine(p.constBegin(), p.constEnd(), typedIn); + const int indent = Indenter::instance().indentForBottomLine(it, p.constBegin(), p.constEnd(), typedIn); const QString trimmed = line.trimmed(); // Indent the line in the list so that the formatter code sees the indented line.