<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [clang-format] [[nodiscard]] causes && to be miss interpreted as BinaryOperators"
href="https://bugs.llvm.org/show_bug.cgi?id=45942">45942</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[clang-format] [[nodiscard]] causes && to be miss interpreted as BinaryOperators
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Formatter
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mydeveloperday@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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=';'</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>