clang官方给出了代码风格配置时的各个选项的说明:
clang内置了以下几种基础风格:
-
LLVM
A style complying with the LLVM coding standards -
Google
A style complying with Google’s C++ style guide -
Chromium
A style complying with Chromium’s style guide -
Mozilla
A style complying with Mozilla’s style guide -
WebKit
A style complying with WebKit’s style guide -
Microsoft
A style complying with Microsoft’s style guide -
GNU
A style complying with the GNU coding standards
关于语句块的大括号的位置,本人最喜欢的还是allman风格:左大括号和右大括号各自单独占一行,并且上下对齐。
BS_Allman
(in configuration: Allman
) Always break before braces.
namespace N
{
enum E
{
E1,
E2,
};
class C
{
public:
C();
};
bool baz(int i)
{
try
{
do
{
switch (i)
{
case 1:
{
foobar();
break;
}
default:
{
break;
}
}
} while (--i);
return true;
}
catch (...)
{
handleError();
return false;
}
}
void foo(bool b)
{
if (b)
{
baz(2);
}
else
{
baz(5);
}
}
void bar() { foo(true); }
} // namespace N