[cfe-dev] clang-format, recognizing alternative binary operator tokens
Nikola Smiljanic
popizdeh at gmail.com
Sat May 3 18:08:01 PDT 2014
Could no-operator-names be on by default?
On Sun, May 4, 2014 at 7:52 AM, Bobby Moretti <bobmoretti at gmail.com> wrote:
> Hello,
>
> clang-format does a really nice job breaking lines with boolean binary
> operators, e.g., && and ||.
>
> The C++ standard provides alternative keywords for these operators
> (and, or). I think clang-format should be able to treat these
> alternative keywords the same as the corresponding binary operators.
> However, with these alternative keywords, clang-format makes
> completely different whitespace choices. For example, using
> clang-format 3.5 from svn r207601, with the default LLVM style options
>
> void foo(void) {
> if (call_some_function() >
> 0 and(some_other_function_result() ==
> 0 or yet_another_result or(something_else == 1))) {
> }
>
> if (call_some_function() > 0 &&
> (some_other_function_result() == 0 || yet_another_result ||
> (something_else == 1))) {
> }
> }
>
> I did some investigation to see what might be causing this behavior.
> It boils down to the LangOptions returned by getFormattingOptions() in
> Format.cpp line 1848. If I add
>
> LangOpts.CXXOperatorNames = 1;
>
> to that function, then clang-format outputs the much more pleasing
>
> void foo(void) {
> if (call_some_function() > 0 and
> (some_other_function_result() == 0 or yet_another_result or
> (something_else == 1))) {
> }
>
> if (call_some_function() > 0 &&
> (some_other_function_result() == 0 || yet_another_result ||
> (something_else == 1))) {
> }
> }
>
> Of course, this should probably not always be enabled.
>
> One option would be to only enable this option if LS_Cpp03 or LS_Cpp11
> were chosen. But C users #including <iso646.h> might want this option,
> and not all C++ users would want it (since for example, MSVC++ does
> not recognize these unless using standards compliant mode).
>
> So another option would be to add a format style option to selectively
> enable this behavior.
>
> Would such a change to clang-format be welcome? If so, what would be
> the preferred implementation?
>
> Thanks,
>
> --
> Bobby Moretti
> bobmoretti at gmail.com
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140504/00746a49/attachment.html>
More information about the cfe-dev
mailing list