forked from OSchip/llvm-project
[clang-format] Fix east const pointer alignment of operators
This patch fixes left pointer alignment after pointer qualifiers of operators. Currently "operator void const*()" is formatted with a space between const and pointer despite setting PointerAlignment to Left. AFAICS this has been broken since clang-format 10. Reviewed By: MyDeveloperDay, curdeius Differential Revision: https://reviews.llvm.org/D99458
This commit is contained in:
parent
9d25ce743a
commit
bc4b0fc53e
|
@ -2957,6 +2957,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
// Space between the type and the * in:
|
||||
// operator void*()
|
||||
// operator char*()
|
||||
// operator void const*()
|
||||
// operator void volatile*()
|
||||
// operator /*comment*/ const char*()
|
||||
// operator volatile /*comment*/ char*()
|
||||
// operator Foo*()
|
||||
|
@ -2964,11 +2966,15 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
// operator std::Foo*()
|
||||
// operator C<T>::D<U>*()
|
||||
// dependent on PointerAlignment style.
|
||||
if (Previous &&
|
||||
(Previous->endsSequence(tok::kw_operator) ||
|
||||
Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
|
||||
Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
|
||||
return (Style.PointerAlignment != FormatStyle::PAS_Left);
|
||||
if (Previous) {
|
||||
if (Previous->endsSequence(tok::kw_operator))
|
||||
return (Style.PointerAlignment != FormatStyle::PAS_Left);
|
||||
if (Previous->is(tok::kw_const) || Previous->is(tok::kw_volatile))
|
||||
return (Style.PointerAlignment != FormatStyle::PAS_Left) ||
|
||||
(Style.SpaceAroundPointerQualifiers ==
|
||||
FormatStyle::SAPQ_After) ||
|
||||
(Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both);
|
||||
}
|
||||
}
|
||||
const auto SpaceRequiredForArrayInitializerLSquare =
|
||||
[](const FormatToken &LSquareTok, const FormatStyle &Style) {
|
||||
|
|
|
@ -12731,6 +12731,27 @@ TEST_F(FormatTest, ConfigurableSpaceAroundPointerQualifiers) {
|
|||
verifyQualifierSpaces("void * const *x = NULL;", PAS_Right, SAPQ_Both);
|
||||
verifyQualifierSpaces("void * const * x = NULL;", PAS_Middle, SAPQ_Both);
|
||||
|
||||
verifyQualifierSpaces("Foo::operator void const*();", PAS_Left, SAPQ_Default);
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Right,
|
||||
SAPQ_Default);
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
|
||||
SAPQ_Default);
|
||||
|
||||
verifyQualifierSpaces("Foo::operator void const*();", PAS_Left, SAPQ_Before);
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Right,
|
||||
SAPQ_Before);
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
|
||||
SAPQ_Before);
|
||||
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Left, SAPQ_After);
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Right, SAPQ_After);
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
|
||||
SAPQ_After);
|
||||
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Left, SAPQ_Both);
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Right, SAPQ_Both);
|
||||
verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle, SAPQ_Both);
|
||||
|
||||
#undef verifyQualifierSpaces
|
||||
|
||||
FormatStyle Spaces = getLLVMStyle();
|
||||
|
@ -18735,6 +18756,10 @@ TEST_F(FormatTest, OperatorSpacing) {
|
|||
verifyFormat("Foo::operator void **();", Style);
|
||||
verifyFormat("Foo::operator void *&();", Style);
|
||||
verifyFormat("Foo::operator void *&&();", Style);
|
||||
verifyFormat("Foo::operator void const *();", Style);
|
||||
verifyFormat("Foo::operator void const **();", Style);
|
||||
verifyFormat("Foo::operator void const *&();", Style);
|
||||
verifyFormat("Foo::operator void const *&&();", Style);
|
||||
verifyFormat("Foo::operator()(void *);", Style);
|
||||
verifyFormat("Foo::operator*(void *);", Style);
|
||||
verifyFormat("Foo::operator*();", Style);
|
||||
|
@ -18756,6 +18781,7 @@ TEST_F(FormatTest, OperatorSpacing) {
|
|||
|
||||
verifyFormat("Foo::operator&();", Style);
|
||||
verifyFormat("Foo::operator void &();", Style);
|
||||
verifyFormat("Foo::operator void const &();", Style);
|
||||
verifyFormat("Foo::operator()(void &);", Style);
|
||||
verifyFormat("Foo::operator&(void &);", Style);
|
||||
verifyFormat("Foo::operator&();", Style);
|
||||
|
@ -18764,6 +18790,7 @@ TEST_F(FormatTest, OperatorSpacing) {
|
|||
verifyFormat("Foo::operator&&();", Style);
|
||||
verifyFormat("Foo::operator**();", Style);
|
||||
verifyFormat("Foo::operator void &&();", Style);
|
||||
verifyFormat("Foo::operator void const &&();", Style);
|
||||
verifyFormat("Foo::operator()(void &&);", Style);
|
||||
verifyFormat("Foo::operator&&(void &&);", Style);
|
||||
verifyFormat("Foo::operator&&();", Style);
|
||||
|
@ -18784,6 +18811,11 @@ TEST_F(FormatTest, OperatorSpacing) {
|
|||
verifyFormat("Foo::operator void*();", Style);
|
||||
verifyFormat("Foo::operator void**();", Style);
|
||||
verifyFormat("Foo::operator void*&();", Style);
|
||||
verifyFormat("Foo::operator void*&&();", Style);
|
||||
verifyFormat("Foo::operator void const*();", Style);
|
||||
verifyFormat("Foo::operator void const**();", Style);
|
||||
verifyFormat("Foo::operator void const*&();", Style);
|
||||
verifyFormat("Foo::operator void const*&&();", Style);
|
||||
verifyFormat("Foo::operator/*comment*/ void*();", Style);
|
||||
verifyFormat("Foo::operator/*a*/ const /*b*/ void*();", Style);
|
||||
verifyFormat("Foo::operator/*a*/ volatile /*b*/ void*();", Style);
|
||||
|
@ -18805,6 +18837,7 @@ TEST_F(FormatTest, OperatorSpacing) {
|
|||
|
||||
verifyFormat("Foo::operator&();", Style);
|
||||
verifyFormat("Foo::operator void&();", Style);
|
||||
verifyFormat("Foo::operator void const&();", Style);
|
||||
verifyFormat("Foo::operator/*comment*/ void&();", Style);
|
||||
verifyFormat("Foo::operator/*a*/ const /*b*/ void&();", Style);
|
||||
verifyFormat("Foo::operator/*a*/ volatile /*b*/ void&();", Style);
|
||||
|
@ -18815,6 +18848,7 @@ TEST_F(FormatTest, OperatorSpacing) {
|
|||
|
||||
verifyFormat("Foo::operator&&();", Style);
|
||||
verifyFormat("Foo::operator void&&();", Style);
|
||||
verifyFormat("Foo::operator void const&&();", Style);
|
||||
verifyFormat("Foo::operator/*comment*/ void&&();", Style);
|
||||
verifyFormat("Foo::operator/*a*/ const /*b*/ void&&();", Style);
|
||||
verifyFormat("Foo::operator/*a*/ volatile /*b*/ void&&();", Style);
|
||||
|
@ -18850,6 +18884,7 @@ TEST_F(FormatTest, OperatorSpacing) {
|
|||
|
||||
verifyFormat("Foo::operator&();", Style);
|
||||
verifyFormat("Foo::operator void &();", Style);
|
||||
verifyFormat("Foo::operator void const &();", Style);
|
||||
verifyFormat("Foo::operator()(void &);", Style);
|
||||
verifyFormat("Foo::operator&(void &);", Style);
|
||||
verifyFormat("Foo::operator&();", Style);
|
||||
|
@ -18857,6 +18892,7 @@ TEST_F(FormatTest, OperatorSpacing) {
|
|||
|
||||
verifyFormat("Foo::operator&&();", Style);
|
||||
verifyFormat("Foo::operator void &&();", Style);
|
||||
verifyFormat("Foo::operator void const &&();", Style);
|
||||
verifyFormat("Foo::operator()(void &&);", Style);
|
||||
verifyFormat("Foo::operator&&(void &&);", Style);
|
||||
verifyFormat("Foo::operator&&();", Style);
|
||||
|
|
Loading…
Reference in New Issue