【发布时间】:2016-11-21 20:22:55
【问题描述】:
Clang 格式一直在这样做:
bool importSomethingIn( const boost::property_tree::ptree& inBoostTree,
int inSomeIndex,
std::shared_ptr<Something>
inSomething,
int x,
int y );
当我希望它这样做时:
bool importSomethingIn( const boost::property_tree::ptree& inBoostTree,
int inSomeIndex,
std::shared_ptr<Something> inSomething,
int x,
int y );
请注意,它在符号inSomething 之前添加了换行符和缩进。似乎总是导致这种行为的模板化类型。
我怎样才能阻止它这样做?
这是我当前的 .clang 格式:
BasedOnStyle: LLVM
Language: Cpp
AccessModifierOffset: -4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: true
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
CommentPragmas: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DerivePointerBinding: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: true
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
PointerBindsToType: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: true
Standard: Cpp11
TabWidth: 8
UseTab: Never
编辑:我正在使用 2016 年 7 月在 github 上获得的 here 的 clang 格式 Xcode 插件(首先安装 Alcatraz,然后使用 Aclatraz 安装 clang 格式插件)。我不完全确定 clang 格式的二进制文件在哪里,因此没有看到插件附带的版本号。
但是,根据以下建议,我使用 Homebrew 安装了 clang-format,它为我提供了 3.9.0 版。然后我将 Xcode 插件设置为“使用系统 clang-format”,我得到了想要的结果,所以我猜它一定是一个错误。
【问题讨论】:
-
您使用的是哪个版本的 clang-format?使用您的示例代码和 .clang-format,我可以使用 clang-format 3.8.0(在 Windows 上)获得所需的输出。
-
相同 - 在 Mac 上使用安装了 Homebrew 的 clang 格式版本 3.9.0 (tags/google/stable/2016-06-27) 获得所需的输出;使用上述选项文件从命令行运行 clang-format。
标签: c++ clang-format