This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG393e197cd6eb: [clang-format] Don't move qualifiers past pointers-to-member (authored by rymiel).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D144537/new/ https://reviews.llvm.org/D144537 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 @@ -420,6 +420,16 @@ // don't adjust macros verifyFormat("const INTPTR a;", "const INTPTR a;", Style); + + // Pointers to members + verifyFormat("int S::*a;", Style); + verifyFormat("int const S::*a;", "const int S:: *a;", Style); + verifyFormat("int const S::*const a;", "const int S::* const a;", Style); + verifyFormat("int A::*const A::*p1;", Style); + verifyFormat("float (C::*p)(int);", Style); + verifyFormat("float (C::*const p)(int);", Style); + verifyFormat("float (C::*p)(int) const;", Style); + verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", Style); } TEST_F(QualifierFixerTest, LeftQualifier) { @@ -565,6 +575,16 @@ // don't adjust macros verifyFormat("INTPTR const a;", "INTPTR const a;", Style); + + // Pointers to members + verifyFormat("int S::*a;", Style); + verifyFormat("const int S::*a;", "int const S:: *a;", Style); + verifyFormat("const int S::*const a;", "int const S::* const a;", Style); + verifyFormat("int A::*const A::*p1;", Style); + verifyFormat("float (C::*p)(int);", Style); + verifyFormat("float (C::*const p)(int);", Style); + verifyFormat("float (C::*p)(int) const;", Style); + verifyFormat("const float (C::*p)(int);", "float const (C::*p)(int);", Style); } TEST_F(QualifierFixerTest, ConstVolatileQualifiersOrder) { Index: clang/lib/Format/QualifierAlignmentFixer.cpp =================================================================== --- clang/lib/Format/QualifierAlignmentFixer.cpp +++ clang/lib/Format/QualifierAlignmentFixer.cpp @@ -280,8 +280,11 @@ // The case `const Foo &&` -> `Foo const &&` // The case `const std::Foo &&` -> `std::Foo const &&` // The case `const std::Foo<T> &&` -> `std::Foo<T> const &&` - while (Next && Next->isOneOf(tok::identifier, tok::coloncolon)) + // However, `const Bar::*` remains the same. + while (Next && Next->isOneOf(tok::identifier, tok::coloncolon) && + !Next->startsSequence(tok::coloncolon, tok::star)) { Next = Next->Next; + } if (Next && Next->is(TT_TemplateOpener)) { Next = Next->MatchingParen; // Move to the end of any template class members e.g.
Index: clang/unittests/Format/QualifierFixerTest.cpp =================================================================== --- clang/unittests/Format/QualifierFixerTest.cpp +++ clang/unittests/Format/QualifierFixerTest.cpp @@ -420,6 +420,16 @@ // don't adjust macros verifyFormat("const INTPTR a;", "const INTPTR a;", Style); + + // Pointers to members + verifyFormat("int S::*a;", Style); + verifyFormat("int const S::*a;", "const int S:: *a;", Style); + verifyFormat("int const S::*const a;", "const int S::* const a;", Style); + verifyFormat("int A::*const A::*p1;", Style); + verifyFormat("float (C::*p)(int);", Style); + verifyFormat("float (C::*const p)(int);", Style); + verifyFormat("float (C::*p)(int) const;", Style); + verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", Style); } TEST_F(QualifierFixerTest, LeftQualifier) { @@ -565,6 +575,16 @@ // don't adjust macros verifyFormat("INTPTR const a;", "INTPTR const a;", Style); + + // Pointers to members + verifyFormat("int S::*a;", Style); + verifyFormat("const int S::*a;", "int const S:: *a;", Style); + verifyFormat("const int S::*const a;", "int const S::* const a;", Style); + verifyFormat("int A::*const A::*p1;", Style); + verifyFormat("float (C::*p)(int);", Style); + verifyFormat("float (C::*const p)(int);", Style); + verifyFormat("float (C::*p)(int) const;", Style); + verifyFormat("const float (C::*p)(int);", "float const (C::*p)(int);", Style); } TEST_F(QualifierFixerTest, ConstVolatileQualifiersOrder) { Index: clang/lib/Format/QualifierAlignmentFixer.cpp =================================================================== --- clang/lib/Format/QualifierAlignmentFixer.cpp +++ clang/lib/Format/QualifierAlignmentFixer.cpp @@ -280,8 +280,11 @@ // The case `const Foo &&` -> `Foo const &&` // The case `const std::Foo &&` -> `std::Foo const &&` // The case `const std::Foo<T> &&` -> `std::Foo<T> const &&` - while (Next && Next->isOneOf(tok::identifier, tok::coloncolon)) + // However, `const Bar::*` remains the same. + while (Next && Next->isOneOf(tok::identifier, tok::coloncolon) && + !Next->startsSequence(tok::coloncolon, tok::star)) { Next = Next->Next; + } if (Next && Next->is(TT_TemplateOpener)) { Next = Next->MatchingParen; // Move to the end of any template class members e.g.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits