Reputation: 736
I'm using a deprecated attribute in my code and I haven't found a clang-format documented way to break after the C++ attribute. I would like that the definition of the do_not_use()
function starts on a next line after the [[deprecated]]
attribute.
Is there a way to break after C++ attributes?
Current state:
[[deprecated("Will be removed in version 2.3.0 as it doesn't support "
"multi-threading processing. "
"Use mt_process_info() instead")]] void
do_not_use()
{
std::cout << "This function should not be used" << std::endl;
}
Desired state:
[[deprecated("Will be removed in version 2.3.0 as it doesn't support "
"multi-threading processing. "
"Use mt_process_info() instead")]]
void do_not_use()
{
std::cout << "This function should not be used" << std::endl;
}
.clang-format:
Language: Cpp
Standard: c++20
AccessModifierOffset: 0
AlignEscapedNewlines: Right
AlignOperands: true
AllowShortFunctionsOnASingleLine: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
ColumnLimit: 100
Cpp11BracedListStyle: true
IncludeBlocks: Regroup
IndentAccessModifiers: true
IndentCaseLabels: true
IndentWidth: 4
PointerAlignment: Left
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
UseTab: Never
I've tried fiddling with the AttributeMacros
and StatementAttributeLikeMacros
clang-format
settings but I haven't found a solution for stated problem.
Upvotes: 1
Views: 1040
Reputation: 145
Good news, a very recent clang-format commit (https://github.com/llvm/llvm-project/commit/a28f0747c2f3728bd8a6f64f7c8ba80b4e0cda9f) has added a new format option: BreakAfterAttributes
.
Using BreakAfterAttributes: Always
gives the output you want:
clang-format --style="{BreakAfterAttributes: Always}"
[[deprecated("Will be removed in version 2.3.0 as it doesn't support "
"multi-threading processing. "
"Use mt_process_info() instead")]]
void do_not_use() {
std::cout << "This function should not be used" << std::endl;
}
Since this option is so new, it isn't yet in any released version, but it is guaranteed to be in version 16, or you may build clang-format from source.
Upvotes: 2