[llvm-bugs] [Bug 49354] New: clang-format: Treat macro as a if/else if/else conditional
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Feb 25 08:15:59 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49354
Bug ID: 49354
Summary: clang-format: Treat macro as a if/else if/else
conditional
Product: clang
Version: 11.0
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Formatter
Assignee: unassignedclangbugs at nondot.org
Reporter: vlovich at gmail.com
CC: djasper at google.com, klimek at google.com,
llvm-bugs at lists.llvm.org
.clang-format is configured such that `} else {` is the format of conditional
statements. The toy repro of the issue is this:
% cat test.cpp
#define IF(cond) if (cond)
IF (true) {
doSomething();
} else {
}
Today:
% clang-format --style=file test.cpp
IF (true) { doSomething(); }
else {
}
It would be nice to be able to specify a list of macros to treat as if/else
if/else conditional statements (similarly to other macro control options like
ForEachMacros) so that the brace alignment happens correctly.
The toy example isn't contrived, just reduced. The KJ library (part of
cap'n'proto) has a KJ_IF_MAYBE that unwraps the kj::Maybe<T> object (equivalent
to std::optional) and returns the internal pointer. So typically there will be
code like:
KJ_IF_MAYBE(value, maybeSomeValue) {
doSomethingWith(*value);
} else {
}
The .clang-format in use for these examples is:
---
Language: Cpp
Standard: c++17
ColumnLimit: 100
SortIncludes: false
AllowShortIfStatementsOnASingleLine: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IndentWidth: 2
IndentCaseBlocks: true
IndentCaseLabels: true
PointerAlignment: Left
DerivePointerAlignment: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
Cpp11BracedListStyle: true
--
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/20210225/e5d681df/attachment.html>
More information about the llvm-bugs
mailing list