[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
This commit is contained in:
Jonathan Coe 2020-05-05 14:05:00 +01:00
parent 1de4e56933
commit 047898c9aa
2 changed files with 7 additions and 0 deletions

View File

@ -1852,6 +1852,10 @@ private:
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;

View File

@ -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) {