1

以下は私のclang形式です

---
AccessModifierOffset: '-4'
AlignConsecutiveAssignments: 'true'
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortIfStatementsOnASingleLine: 'true'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakTemplateDeclarations: 'true'
BinPackArguments: 'true'
BinPackParameters: 'true'
BreakBeforeBraces: Allman
BreakConstructorInitializersBeforeComma: 'true'
ColumnLimit: '80'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
Cpp11BracedListStyle: 'true'
IndentCaseLabels: 'false'
IndentWidth: '4'
MaxEmptyLinesToKeep: '2'
NamespaceIndentation: All
PointerAlignment: Left
SpaceAfterCStyleCast: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: ControlStatements
SpacesBeforeTrailingComments: '1'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Auto
TabWidth: '4'
UseTab: Always

...

しかし、C ++ファイルで実行すると、次のような結果が得られます(コードは意味不明なコピーアンドペーストですが、アラインされていない割り当ての問題のある領域は、コードで壊れていると思われるものの逐語的なコピーです)

template <class X>
void prettyPrint(std::ostream& o, const X* x)
{
    o << "*{";
    if (x)
    {
        prettyPrint(o, *x);
    }
    else
    {
        o << "NULL";
    }
    // I wanted the following assignments to align !!!!
    using value_type           = std::decay_t<decltype(state)>;
    using difference_type   = std::ptrdiff_t;
    using reference         = value_type&;
    using pointer             = value_type*;
    using iterator_category = std::input_iterator_tag;

    o << "}";
}

設定した

AlignConsecutiveAssignments: 'true'

上記の動作は間違っていると思います。残りの部分で.clang-format結果を台無しにする何かがありますか?それとも、これをバグとして報告する必要がありますか?

4

2 に答える 2

4

UseTab: Always少なくとも 1 つのタブストップから次のタブストップにまたがる空白を埋める必要があるときはいつでも、を使用するとタブが使用されます。ただし、これらのタブは、それらの前にあるステートメントの長さがさまざまであり、異なるタブ ストップに移動するタブを出力するため、整列しません。

適切な代替手段はUseTab: ForIndentation、名前が示すように、インデントにのみタブを使用するものを使用することです。

または、UseTab: Neverタブを使用しないものでも。

于 2016-03-28T12:18:42.080 に答える
1

UseTab: Always投稿した .clang-format スニペットの行を削除することで、希望どおりにフォーマットできました。

template <class X>
void prettyPrint(std::ostream& o, const X* x)
{
    o << "*{";
    if (x)
    {
        prettyPrint(o, *x);
    }
    else
    {
        o << "NULL";
    }
    // I wanted the following assignments to align !!!!
    using value_type        = std::decay_t<decltype(state)>;
    using difference_type   = std::ptrdiff_t;
    using reference         = value_type&;
    using pointer           = value_type*;
    using iterator_category = std::input_iterator_tag;

    o << "}";
}

理由は・・・見当がつきませんでした。

編集:UseTab: ForIndentationまたはNever機能しますが、Always壊れるだけです

于 2016-03-28T12:10:36.580 に答える