Clang-Format不会缩进头文件中的模板函数

问题描述 投票:0回答:1

我在使用clang格式时遇到此问题,无法正确缩进头文件。例如,我在一个类中有一个模板函数,我希望它的格式如下:

template <class T>
class Thing {
public:
    T function() {
        stuff();
        return T;
    }
}

我感觉这种缩进会自动发生,但是事实并非如此。当我运行Clang格式时,我的功能代码像这样缩进:

template <class T>
class Thing {
public:
    T function() {
    stuff();
    return T;
    }
}

如何获得头文件中的代码,使其格式像最上面的而不是最下面的一样?

下面是我的.clang格式文件:

BasedOnStyle: LLVM
AccessModifierOffset: -4
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping:
  AfterClass: false
  AfterControlStatement: false
  AfterEnum: false
  AfterFunction: false
  AfterNamespace: false
  AfterStruct: false
  AfterUnion: false
  AfterExternBlock: false
  BeforeCatch: false
  BeforeElse: false
  IndentBraces: false
  SplitEmptyFunction: false
BreakConstructorInitializers: AfterColon
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: false
IndentCaseLabels: false
IndentWidth: 4
Language: Cpp
NamespaceIndentation: All
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakComment: 2000
PenaltyBreakString: 3000
PenaltyBreakFirstLessLess: 1000
PenaltyExcessCharacter: 100000
PenaltyReturnTypeOnItsOwnLine: 10000
PointerAlignment: Left
SortIncludes: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInParentheses: false
Standard: Cpp11
UseTab: ForIndentation
clang-format
1个回答
0
投票

我在this online clang format generator中打开了您的配置文件,并寻找了适用于您的示例代码的设置。

© www.soinside.com 2019 - 2024. All rights reserved.