在 VsCode 中,我想将我的 Clang 格式更改为:
class Test {
public:
Test() : tmp(0)
{
if (0 == 0) {
std::cout << "hello" << std::endl;
}
}
~Test();
protected:
private:
int tmp;
};
但目前我得到了:
class Test {
public:
Test() : tmp(0) {
if (0 == 0) {
std::cout << "hello" << std::endl;
}
}
~Test();
protected:
private:
int tmp;
};
我的 CLang 设置:
{ BasedOnStyle: Google, IndentWidth: 4 }
最佳答案
关于大括号断开样式
您要断开的大括号位于函数之后,因此您需要将其添加到 Clang 设置中:
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
您可以在 Clang-Format Style Options 中找到其他 BraceWrapping
选项.
关于修饰符缩进
目前,Clang 仅提供一个选项来调整修饰符缩进 - AccessModifierOffset
。此选项将从您设置的 IndentWidth
向内或向外偏移。目前不可能使修饰符缩进标准。还好目前正在讨论审核中here .
您可以设置它以减少烦人:
AccessModifierOffset: 0
如果您设置了以上所有选项,您会得到以下结果:
class Test {
public:
Test() : tmp(0)
{
if (0 == 0) {
std::cout << "hello" << std::endl;
}
}
~Test();
protected:
private:
int tmp;
};
关于c++ - 更改 {} 和访问修饰符的 Clang 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69871410/