[PATCH] D120445: [clang-format] Treat && followed by noexcept operator as a binary operator inside template arguments

Luis Penagos via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 23 17:43:58 PST 2022


penagos created this revision.
penagos added reviewers: curdeius, MyDeveloperDay.
penagos published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120445

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9512,6 +9512,7 @@
   verifyFormat("f(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
                "      .template operator()<A>());",
                getLLVMStyleWithColumns(35));
+  verifyFormat("bool_constant<a && noexcept(f())>");
 
   // Not template parameters.
   verifyFormat("return a < b && c > d;");
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2066,6 +2066,10 @@
       return TT_UnaryOperator;
 
     const FormatToken *NextToken = Tok.getNextNonComment();
+
+    if (InTemplateArgument && NextToken && NextToken->is(tok::kw_noexcept))
+      return TT_BinaryOperator;
+
     if (!NextToken ||
         NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_noexcept) ||
         NextToken->canBePointerOrReferenceQualifier() ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120445.410982.patch
Type: text/x-patch
Size: 1078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220224/61c20925/attachment-0001.bin>


More information about the cfe-commits mailing list