diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -328,14 +328,17 @@ if (Next->is(tok::comment) && Next->getNextNonComment()) Next = Next->getNextNonComment(); assert(Next->MatchingParen && "Missing template closer"); - Next = Next->MatchingParen->Next; + Next = Next->MatchingParen; + if (Next->ClosesRequiresClause) + return Next; + Next = Next->Next; // Move to the end of any template class members e.g. // `Foo::iterator`. if (Next && Next->startsSequence(tok::coloncolon, tok::identifier)) Next = Next->Next->Next; if (Next && Next->is(QualifierType)) { - // Remove the const. + // Move the qualifier. insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier); removeToken(SourceMgr, Fixes, Next); return Next; @@ -344,7 +347,7 @@ if (Next && Next->Next && Next->Next->isOneOf(tok::amp, tok::ampamp, tok::star)) { if (Next->is(QualifierType)) { - // Remove the qualifier. + // Move the qualifier. insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier); removeToken(SourceMgr, Fixes, Next); return Next; diff --git a/clang/unittests/Format/QualifierFixerTest.cpp b/clang/unittests/Format/QualifierFixerTest.cpp --- a/clang/unittests/Format/QualifierFixerTest.cpp +++ b/clang/unittests/Format/QualifierFixerTest.cpp @@ -858,6 +858,21 @@ Style); } +TEST_F(QualifierFixerTest, WithConstraints) { + FormatStyle Style = getLLVMStyle(); + Style.QualifierAlignment = FormatStyle::QAS_Custom; + Style.QualifierOrder = {"constexpr", "type"}; + + verifyFormat("template \n" + " requires Concept\n" + "constexpr constructor();", + Style); + verifyFormat("template \n" + " requires Concept1 && Concept2\n" + "constexpr constructor();", + Style); +} + TEST_F(QualifierFixerTest, DisableRegions) { FormatStyle Style = getLLVMStyle(); Style.QualifierAlignment = FormatStyle::QAS_Custom;