[llvm-bugs] [Bug 45942] New: [clang-format] [[nodiscard]] causes && to be miss interpreted as BinaryOperators

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 15 05:31:44 PDT 2020


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

            Bug ID: 45942
           Summary: [clang-format] [[nodiscard]] causes && to be miss
                    interpreted as BinaryOperators
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mydeveloperday at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Using

---
Language: Cpp
BasedOnStyle: Chromium

The following code will case

Will format the move constructor (and other areas) incorrectly just because of
the addition of [[nodiscard]] to the class.

e.g.
S(S&&) = default;
vs
S(S &&) = default;


-------------------------------------------------
namespace n1 {
struct S {
  S(const S&) = default;
  S(S&) = default;
  S(S&&) = default;
  S(int&&) {}

  void x() const&;
  void x() &;
  void x() &&;
  void y() && noexcept;
};
}  // namespace n1

namespace n2 {
struct [[nodiscard]] S {
  // OK
  S(const S&) = default;
  S(S&) = default;

  // Inconsistent space before &&
  S(S &&) = default;
  S(int&&) {}

  // OK
  void x() const&;

  // Lack of space betwen () and &&
  void x()&;
  void x()&&;
  void y()&& noexcept;
};
}  // namespace n2
-------------------------------------------------

This is caused by && being interpreted as a BinaryOperator in the second case

AnnotatedTokens(L=1):
 M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=identifier L=1 PPK=2 FakeLParens=2/
FakeRParens=0 II=0xfc5800 Text='S'
 M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=l_paren L=2 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 B=0 BK=0 P=140 Name=identifier L=3 PPK=2 FakeLParens=
FakeRParens=0 II=0xfc5800 Text='S'
 M=0 C=0 T=PointerOrReference S=0 B=0 BK=0 P=230 Name=ampamp L=5 PPK=2
FakeLParens= FakeRParens=0 II=0x0 Text='&&'
 M=0 C=0 T=Unknown S=0 B=0 BK=0 P=45 Name=r_paren L=6 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=BinaryOperator S=1 B=0 BK=0 P=22 Name=equal L=8 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='='
 M=0 C=1 T=Unknown S=1 B=0 BK=0 P=130 Name=default L=16 PPK=2 FakeLParens=
FakeRParens=1 II=0xfc4530 Text='default'
 M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=17 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text=';'


vs


AnnotatedTokens(L=1):
 M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=identifier L=1 PPK=2 FakeLParens=2/
FakeRParens=0 II=0xfc5800 Text='S'
 M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=l_paren L=2 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 B=0 BK=0 P=59 Name=identifier L=3 PPK=2 FakeLParens=5/
FakeRParens=0 II=0xfc5800 Text='S'
 M=0 C=0 T=BinaryOperator S=1 B=0 BK=0 P=45 Name=ampamp L=6 PPK=2 FakeLParens=
FakeRParens=1 II=0x0 Text='&&'
 M=0 C=0 T=Unknown S=0 B=0 BK=0 P=45 Name=r_paren L=7 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=BinaryOperator S=1 B=0 BK=0 P=22 Name=equal L=9 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text='='
 M=0 C=1 T=Unknown S=1 B=0 BK=0 P=22 Name=default L=17 PPK=2 FakeLParens=
FakeRParens=1 II=0xfc4530 Text='default'
 M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=18 PPK=2 FakeLParens=
FakeRParens=0 II=0x0 Text=';'

-- 
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/20200515/9c876f16/attachment.html>


More information about the llvm-bugs mailing list