This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG46f6c834d9f9: [clang-format] Fix QualifierOrder breaking the code with requires clause. (authored by curdeius).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D120309/new/ https://reviews.llvm.org/D120309 Files: clang/lib/Format/QualifierAlignmentFixer.cpp clang/unittests/Format/QualifierFixerTest.cpp Index: clang/unittests/Format/QualifierFixerTest.cpp =================================================================== --- clang/unittests/Format/QualifierFixerTest.cpp +++ 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 <typename T>\n" + " requires Concept<F>\n" + "constexpr constructor();", + Style); + verifyFormat("template <typename T>\n" + " requires Concept1<F> && Concept2<F>\n" + "constexpr constructor();", + Style); +} + TEST_F(QualifierFixerTest, DisableRegions) { FormatStyle Style = getLLVMStyle(); Style.QualifierAlignment = FormatStyle::QAS_Custom; Index: clang/lib/Format/QualifierAlignmentFixer.cpp =================================================================== --- clang/lib/Format/QualifierAlignmentFixer.cpp +++ 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<int>::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;
Index: clang/unittests/Format/QualifierFixerTest.cpp =================================================================== --- clang/unittests/Format/QualifierFixerTest.cpp +++ 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 <typename T>\n" + " requires Concept<F>\n" + "constexpr constructor();", + Style); + verifyFormat("template <typename T>\n" + " requires Concept1<F> && Concept2<F>\n" + "constexpr constructor();", + Style); +} + TEST_F(QualifierFixerTest, DisableRegions) { FormatStyle Style = getLLVMStyle(); Style.QualifierAlignment = FormatStyle::QAS_Custom; Index: clang/lib/Format/QualifierAlignmentFixer.cpp =================================================================== --- clang/lib/Format/QualifierAlignmentFixer.cpp +++ 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<int>::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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits