https://github.com/mydeveloperday created https://github.com/llvm/llvm-project/pull/78176
No need to add an extract space if merging the characters doesn't cause a problem, hence ) and ! as well as ( do not require the extraneous space. Fixes #78166 >From 9d29ad06ff71b855a43f57b339990e41f206ac8d Mon Sep 17 00:00:00 2001 From: mydeveloperday <mydeveloper...@gmail.com> Date: Mon, 15 Jan 2024 15:42:59 +0000 Subject: [PATCH] [clang-format] adds a space after not inside macros No need to add an extract space if merging the characters doesn't cause a problem, hence ) and ! as well as ( do not require the extraneous space. --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 227aa0b97af6ba..e45271809e8085 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return true; } if (Left.is(TT_UnaryOperator)) { - if (Right.isNot(tok::l_paren)) { + if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) { // The alternative operators for ~ and ! are "compl" and "not". // If they are used instead, we do not want to combine them with // the token to the right, unless that is a left paren. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 8f115fb8cbf0fb..54b8593fb98d42 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -24159,6 +24159,8 @@ TEST_F(FormatTest, AlternativeOperators) { verifyFormat("int a compl(5);"); verifyFormat("int a not(5);"); + verifyFormat("v(not)"); + verifyFormat("v(not!)"); /* FIXME handle alternate tokens * https://en.cppreference.com/w/cpp/language/operator_alternative _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits