Format: support inline namespaces

Correct handling for C++17 inline namespaces.  We would previously fail to
identify the inline namespaces as a namespace name since multiple ones may be
concatenated now with C++17.

llvm-svn: 251690
This commit is contained in:
Saleem Abdulrasool 2015-10-30 05:07:56 +00:00
parent 49359bf3d7
commit 328085f325
2 changed files with 8 additions and 1 deletions

View File

@ -1367,7 +1367,7 @@ void UnwrappedLineParser::parseNamespace() {
const FormatToken &InitialToken = *FormatTok;
nextToken();
if (FormatTok->Tok.is(tok::identifier))
while (FormatTok->isOneOf(tok::identifier, tok::coloncolon))
nextToken();
if (FormatTok->Tok.is(tok::l_brace)) {
if (ShouldBreakBeforeBrace(Style, InitialToken))

View File

@ -2192,6 +2192,13 @@ TEST_F(FormatTest, FormatsNamespaces) {
"} // my_namespace\n"
"#endif // HEADER_GUARD"));
EXPECT_EQ("namespace A::B {\n"
"class C {};\n"
"}",
format("namespace A::B {\n"
"class C {};\n"
"}"));
FormatStyle Style = getLLVMStyle();
Style.NamespaceIndentation = FormatStyle::NI_All;
EXPECT_EQ("namespace out {\n"