[llvm-bugs] [Bug 45338] New: AllowShortIfStatementsOnASingleLine: WithoutElse broken
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Mar 28 11:11:01 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45338
Bug ID: 45338
Summary: AllowShortIfStatementsOnASingleLine: WithoutElse
broken
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Formatter
Assignee: unassignedclangbugs at nondot.org
Reporter: pablomg+llvm at eskapa.be
CC: djasper at google.com, klimek at google.com,
llvm-bugs at lists.llvm.org
$ cat test.cpp
int main() {
if (true) { function(); }
if (true) function();
if (true) { function(); } else function();
if (true) { function(); } else { function(); }
if (true) function(); else function();
if (true) function(); else { function(); }
}
$ clang-format test.cpp -style="{BasedOnStyle: google, BreakBeforeBraces:
Allman, AllowShortBlocksOnASingleLine: Always,
AllowShortIfStatementsOnASingleLine: WithoutElse}"
int main()
{
if (true) { function(); }
if (true) function();
if (true) { function(); }
else
function();
if (true) { function(); }
else
{
function();
}
if (true)
function();
else
function();
if (true)
function();
else
{
function();
}
}
According to the clang-format 11 documentation,
AllowShortIfStatementsOnASingleLine: WithoutElse means the following: "Without
else put short ifs on the same line only if the else is not a compound
statement.". So the expected result should be:
$ clang-format test.cpp -style="{BasedOnStyle: google, BreakBeforeBraces:
Allman, AllowShortBlocksOnASingleLine: Always,
AllowShortIfStatementsOnASingleLine: WithoutElse}"
int main()
{
if (true) { function(); }
if (true) function();
if (true) { function(); }
else
function();
if (true)
{
function();
}
else
{
function();
}
if (true) function();
else
function();
if (true)
function();
else
{
function();
}
}
I don't use BreakBeforeBraces: Attach but it seems broken too:
$ ../bin/clang-format test.cpp -style="{BasedOnStyle: google,
BreakBeforeBraces: Attach, AllowShortBlocksOnASingleLine: Always,
AllowShortIfStatementsOnASingleLine: WithoutElse}"
int main() {
if (true) { function(); }
if (true) function();
if (true) {
function();
} else
function();
if (true) {
function();
} else {
function();
}
if (true)
function();
else
function();
if (true)
function();
else {
function();
}
}
Might be related to bug 25010 (https://bugs.llvm.org/show_bug.cgi?id=25010) but
I'm not sure.
--
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/20200328/24038052/attachment-0001.html>
More information about the llvm-bugs
mailing list