Skip to content

Commit

Permalink
[clang-format] [PR46157] Wrong spacing of negative literals with use …
Browse files Browse the repository at this point in the history
…of operator

Summary:
see https://bugs.llvm.org/show_bug.cgi?id=46157

Reviewed By: curdeius

Differential Revision: https://reviews.llvm.org/D80933
  • Loading branch information
mydeveloperday committed Jun 3, 2020
1 parent 6a0484f commit 6de794e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -978,16 +978,18 @@ class AnnotatingParser {
if (CurrentToken->isOneOf(tok::star, tok::amp))
CurrentToken->setType(TT_PointerOrReference);
consumeToken();
if (CurrentToken && CurrentToken->is(tok::comma) &&
CurrentToken->Previous->isNot(tok::kw_operator))
break;
if (CurrentToken && CurrentToken->Previous->isOneOf(
TT_BinaryOperator, TT_UnaryOperator, tok::comma,
tok::star, tok::arrow, tok::amp, tok::ampamp))
CurrentToken->Previous->setType(TT_OverloadedOperator);
}
if (CurrentToken) {
if (CurrentToken && CurrentToken->is(tok::l_paren))
CurrentToken->setType(TT_OverloadedOperatorLParen);
if (CurrentToken->Previous->is(TT_BinaryOperator))
CurrentToken->Previous->setType(TT_OverloadedOperator);
}
if (CurrentToken && CurrentToken->Previous->is(TT_BinaryOperator))
CurrentToken->Previous->setType(TT_OverloadedOperator);
break;
case tok::question:
if (Tok->is(TT_CSharpNullConditionalLSquare)) {
Expand Down
11 changes: 11 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Expand Up @@ -16429,6 +16429,17 @@ TEST_F(FormatTest, OperatorSpacing) {
verifyFormat("operator&&(int(&&)(), class Foo);", Style);
}

TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) {
FormatStyle Style = getLLVMStyle();
// PR46157
verifyFormat("foo(operator+, -42);", Style);
verifyFormat("foo(operator++, -42);", Style);
verifyFormat("foo(operator--, -42);", Style);
verifyFormat("foo(-42, operator--);", Style);
verifyFormat("foo(-42, operator, );", Style);
verifyFormat("foo(operator, , -42);", Style);
}

TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
// These tests are not in NamespaceFixer because that doesn't
// test its interaction with line wrapping
Expand Down

0 comments on commit 6de794e

Please sign in to comment.