[clang] 047898c - [clang-format] C# always regards && as a binary operator
Jonathan Coe via cfe-commits
cfe-commits at lists.llvm.org
Tue May 5 06:07:16 PDT 2020
Author: Jonathan Coe
Date: 2020-05-05T14:05:00+01:00
New Revision: 047898c9aa1d8858fa0d87f7e349749222cabf22
URL: https://github.com/llvm/llvm-project/commit/047898c9aa1d8858fa0d87f7e349749222cabf22
DIFF: https://github.com/llvm/llvm-project/commit/047898c9aa1d8858fa0d87f7e349749222cabf22.diff
LOG: [clang-format] C# always regards && as a binary operator
Reviewers: krasimir, MyDeveloperDay
Reviewed By: MyDeveloperDay
Subscribers: cfe-commits
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D79414
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 6671284a4734..734dbdc1b6f3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1852,6 +1852,10 @@ class AnnotatingParser {
if (Style.Language == FormatStyle::LK_JavaScript)
return TT_BinaryOperator;
+ // && in C# must be a binary operator.
+ if (Style.isCSharp() && Tok.is(tok::ampamp))
+ return TT_BinaryOperator;
+
const FormatToken *PrevToken = Tok.getPreviousNonComment();
if (!PrevToken)
return TT_UnaryOperator;
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index d8d992e091d9..6f0b1966767d 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -706,6 +706,9 @@ TEST_F(FormatTestCSharp, CSharpSpaces) {
verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style);
verifyFormat(R"(var (key, value))", Style);
+ // `&&` is not seen as a reference.
+ verifyFormat(R"(A == typeof(X) && someBool)", Style);
+
// Not seen as a C-style cast.
verifyFormat(R"(//
foreach ((A a, B b) in someList) {
More information about the cfe-commits
mailing list