llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Emilia Kond (rymiel)

<details>
<summary>Changes</summary>

Simply always return false if tok::ampamp is passed into 
determineUnaryOperatorByUsage.

I've done a fix earlier regarding ampamp becoming an unary operator, this would 
technically supersede that.

I'm not sure why this hasn't been done before, I don't see any downsides.

Fixes https://github.com/llvm/llvm-project/issues/78789

---
Full diff: https://github.com/llvm/llvm-project/pull/78852.diff


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+3) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+4) 


``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 25fcceb8786437..573e986b6939df 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2503,6 +2503,9 @@ class AnnotatingParser {
     if (!PrevToken)
       return true;
 
+    if (Tok.is(tok::ampamp))
+      return false;
+
     // These keywords are deliberately not included here because they may
     // precede only one of unary star/amp and plus/minus but not both.  They 
are
     // either included in determineStarAmpUsage or 
determinePlusMinusCaretUsage.
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 64b2abac5cce53..f8d2b264ee7480 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -309,6 +309,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
   EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_FunctionLBrace);
   EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("if (delete && foo) {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/78852
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to