On Thu, Apr 02, 2020 at 06:07:55PM +0800, Kewen.Lin wrote: > > The above is misformatted. The ? and : shouldn't be indented further than > > the dataref_offset, but usually e.g. for the sake of emacs we add ()s around > > the expression in this case. So: > > tree offset = (dataref_offset > > ? dataref_offset > > : build_int_cst (ref_type, 0)); > > or > > tree offset > > = (dataref_offset > > ? dataref_offset : build_int_cst (ref_type, 0)); > > > > Thanks Jakub! I'll follow this by add () for ternary expression. > With manual added "()", clang-format can get below:
Note, the () isn't about ternary expressions, if everything fits on one line, there is no reason to add ()s, so tree offset = dataref_offset ? dataref_offset : build_int_cst (ref_type, 0); is just fine that way, on the other side int whatever = HOST_WIDE_INT_1U + foobarbaz (qux); should have them too, like: int whatever = (HOST_WIDE_INT_1U + foobarbaz (qux)); or int whatever = HOST_WIDE_INT_1U + foobarbaz (qux); I don't use emacs, but was told that emacs without the ()s would misindent it like (I think): int whatever = HOST_WIDE_INT_1U + foobarbaz (qux); which is what we do not want. > > tree offset > = (dataref_offset ? dataref_offset > : build_int_cst (ref_type, 0)); > > contrib/check_GNU_style.sh didn't complain this, I'm not sure whether > it's possible to add this kind of convention into contrib/clang-format. clang-format is not our official indentation style; I have no problem with the above formatting from readability POV, though unsure what emacs will do with that (but if it moves that : right below the first dataref_offset, no big deal, that is also fine and probably more appropriate if the build_int_cst... is long and would need more wrapping). Jakub