[clang] 24d4f60 - [clang-format] Treat && followed by noexcept operator as a binary operator inside template arguments
Marek Kurdej via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 28 02:55:10 PST 2022
Author: Luis Penagos
Date: 2022-02-28T11:55:04+01:00
New Revision: 24d4f601aa6dd83b46ca41913452d0771a97d603
URL: https://github.com/llvm/llvm-project/commit/24d4f601aa6dd83b46ca41913452d0771a97d603
DIFF: https://github.com/llvm/llvm-project/commit/24d4f601aa6dd83b46ca41913452d0771a97d603.diff
LOG: [clang-format] Treat && followed by noexcept operator as a binary operator inside template arguments
Fixes https://github.com/llvm/llvm-project/issues/44544.
Reviewed By: curdeius, MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D120445
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 36ff757922a9..e3d79aaf9184 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2089,6 +2089,10 @@ class AnnotatingParser {
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() ||
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 8008cce232d3..9a0890f874dd 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9512,6 +9512,8 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
verifyFormat("f(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" .template operator()<A>());",
getLLVMStyleWithColumns(35));
+ verifyFormat("bool_constant<a && noexcept(f())>");
+ verifyFormat("bool_constant<a || noexcept(f())>");
// Not template parameters.
verifyFormat("return a < b && c > d;");
More information about the cfe-commits
mailing list