clang-format:将指针声明的星号(*)与变量名称对齐 [英] clang-format: Align asterisk (*) of pointer declaration with variable name
本文介绍了clang-format:将指针声明的星号(*)与变量名称对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 .clang-format
文件中使用以下选项:
AlignConsecutive注释:true
PointerAlignment:Right
当前格式化结果如下:
char * var1;
SomeOtherType * var2;
int var3;
我预期的结果是:
char * var1; //注意*
的改变位置SomeOtherType * var2;
int var3;
如何配置 clang-format
使用 AlignConsecutiveDeclarations
选项,将asterix(*)与变量名称对齐,而与
类型匹配?
p>请参见 https:// github。 com / llvm-mirror / clang / blob / release_39 / lib / Format / WhitespaceManager.cpp#L327-L340
void WhitespaceManager :: alignConsecutiveDeclarations(){
if(!Style.AlignConsecutiveDeclarations)
return;
// FIXME:目前我们不能正确处理PointerAlignment:Right
// *和&没有对齐并且留下悬空。需要做的事情
//它,但它提出了一致的代码的问题,如:
// const char * const * v1;
// float const * v2;
// SomeVeryLongType const& v3;
AlignTokens(Style,[](Change const& C){return C.IsStartOfDeclName;},
Changes);
}
I am using the following options in my .clang-format
file:
AlignConsecutiveDeclarations: true
PointerAlignment: Right
The current formatting result is the following:
char * var1;
SomeOtherType *var2;
int var3;
The result I was expecting would be:
char *var1; //note the changed position of *
SomeOtherType *var2;
int var3;
How can I configure clang-format
to align the asterix (*) with the variable name rather then with the type when I am
using the AlignConsecutiveDeclarations
option?
解决方案
PointerAlignment: Right
is unfortunately not implemented yet.
See https://github.com/llvm-mirror/clang/blob/release_39/lib/Format/WhitespaceManager.cpp#L327-L340
void WhitespaceManager::alignConsecutiveDeclarations() {
if (!Style.AlignConsecutiveDeclarations)
return;
// FIXME: Currently we don't handle properly the PointerAlignment: Right
// The * and & are not aligned and are left dangling. Something has to be done
// about it, but it raises the question of alignment of code like:
// const char* const* v1;
// float const* v2;
// SomeVeryLongType const& v3;
AlignTokens(Style, [](Change const &C) { return C.IsStartOfDeclName; },
Changes);
}
这篇关于clang-format:将指针声明的星号(*)与变量名称对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文