簡體   English   中英

使用 C++ 屬性后使 clang-format 中斷

[英]Make clang-format break after the usage of C++ attributes

我在我的代碼中使用了一個已棄用的屬性,但我還沒有找到 C++ 屬性后中斷的clang 格式記錄方式。 我希望do_not_use() function 的定義在[[deprecated]]屬性之后的下一行開始。

有沒有辦法在 C++ 屬性之后中斷?

當前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;
}

所需 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 格式:

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

我試過擺弄AttributeMacrosStatementAttributeLikeMacros clang-format設置,但我還沒有找到解決所述問題的方法。

好消息,最近的 clang 格式提交 ( https://github.com/llvm/llvm-project/commit/a28f0747c2f3728bd8a6f64f7c8ba80b4e0cda9f ) 添加了一個新的格式選項: BreakAfterAttributes

使用BreakAfterAttributes: Always提供您想要的 output:

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;
}

由於這個選項太新了,它還沒有出現在任何發布的版本中,但它保證在版本 16 中,或者您可以從源代碼構建 clang-format。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM