[llvm-bugs] [Bug 49868] New: Follow up on bug 46969: clang-format splits bitshift operator >> into > >

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 6 13:49:26 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49868

            Bug ID: 49868
           Summary: Follow up on bug 46969: clang-format splits bitshift
                    operator >> into > >
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ezra at ezisland.org
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Bug 46969 (https://bugs.llvm.org/show_bug.cgi?id=46969) describes how
clang-format (version <= 11) can occasionally split a right-bitshift operator
(>>) into two angle-brackets by inserting a space in between (> >). 

A patch for this issue has been submitted for release 12.x as per
https://reviews.llvm.org/D86581
The review comments acknowledge that some situations in which the bitshift
operator is split are not correctly resolved by the patch (due in part to the
ambiguity introduced by c++14 variable templates).

Since this issue is present in release 12.x and possibly in trunk, I am raising
it as a follow up bug report for 46969.

Consider this simple example which is incorrectly transformed by clang-format
even in release 12.x:

Original:

int main() {
  int x = 0;
  int y = 0;
  return x < y - 1 >> 1;
}

After clang-format:

int main() {
  int x = 0;
  int y = 0;
  return x < y - 1 > > 1; /*<< Code is broken*/
}

I was wondering if there are any mitigation strategies for this issue. This has
cropped up as a problem for developers of source-to-source compilers which emit
c and c++ code that subsequently needs to be formatted. The emitted code might
contain such ambiguous syntax and we would like clang-format to take a more
conservative approach to formatting if possible in order to avoid modifying the
original behavior of the program.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210406/14f87429/attachment.html>


More information about the llvm-bugs mailing list