Skip to content

C# short ternary operator missing space before colon or question mark #58067

@3geek14

Description

@3geek14

I have a file mwe.cs:

var x=cond?"A":"B";
var y=(cond?"A":"B");
Func(cond?"A":"B");
(cond?"A":"B");
cond?"A":"B";

When I run clang-format --style=LLVM mwe.cs, I get the output:

var x = cond ? "A" : "B";
var y = (cond ? "A" : "B");
Func(cond? "A": "B");
(cond? "A": "B");
cond? "A" : "B";

In the variable assignments, the formatting is correct. In the function call, both spaces are missing, and the same in the following line with parentheses around the ternary expression. In the final line, only the space before the question mark is missing.

As is expected, adding spaces to the input file before the ?s and :s does not change the output.

I have clang-format version 15.0.1 installed.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions