From: Daniel Jasper Date: Mon, 27 May 2013 16:36:33 +0000 (+0000) Subject: Improve formatting of templates. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=131884a4bd9b72f8ced8c9f6d2b284f40fde1ea5;p=clang Improve formatting of templates. Before: A < int&& > a; After: A a; Also remove obsolete FIXMEs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182741 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index f2c4da39dc..0a89e9c6bc 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -103,7 +103,8 @@ private: if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace, tok::question, tok::colon)) return false; - if (CurrentToken->isOneOf(tok::pipepipe, tok::ampamp) && + if (CurrentToken->Parent->isOneOf(tok::pipepipe, tok::ampamp) && + CurrentToken->Parent->Type != TT_PointerOrReference && Line.First.isNot(tok::kw_template)) return false; updateParameterCount(Left, CurrentToken); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index d237c0b2f8..fd9678c352 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1420,7 +1420,6 @@ TEST_F(FormatTest, FormatObjCTryCatch) { TEST_F(FormatTest, StaticInitializers) { verifyFormat("static SomeClass SC = { 1, 'a' };"); - // FIXME: Format like enums if the static initializer does not fit on a line. verifyFormat( "static SomeClass WithALoooooooooooooooooooongName = {\n" " 100000000, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n" @@ -1657,13 +1656,10 @@ TEST_F(FormatTest, EmptyLinesInMacroDefinitions) { TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) { verifyFormat("#define A :"); - - // FIXME: Improve formatting of case labels in macros. verifyFormat("#define SOMECASES \\\n" " case 1: \\\n" " case 2\n", getLLVMStyleWithColumns(20)); - verifyFormat("#define A template "); verifyFormat("#define STR(x) #x\n" "f(STR(this_is_a_string_literal{));"); @@ -2767,8 +2763,6 @@ TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) { " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa::\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();"); - // FIXME: Look into whether we should indent 4 from the start or 4 from - // "bbbbb..." here instead of what we are doing now. verifyFormat( "aaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb::\n" " cccccccccccccccccccccccccccccccccccccccccccccc());"); @@ -2962,7 +2956,6 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyGoogleFormat("return sizeof(int**);"); verifyIndependentOfContext("Type **A = static_cast(P);"); verifyGoogleFormat("Type** A = static_cast(P);"); - // FIXME: The newline is wrong. verifyFormat("auto a = [](int **&, int ***) {};"); verifyIndependentOfContext("InvalidRegions[*R] = 0;"); @@ -3074,12 +3067,10 @@ TEST_F(FormatTest, UnderstandsRvalueReferences) { verifyGoogleFormat("int f(int a, char&& b) {}"); verifyGoogleFormat("void f() { int&& a = b; }"); - // FIXME: These require somewhat deeper changes in template arguments - // formatting. - // verifyIndependentOfContext("A a;"); - // verifyIndependentOfContext("A a;"); - // verifyGoogleFormat("A a;"); - // verifyGoogleFormat("A a;"); + verifyIndependentOfContext("A a;"); + verifyIndependentOfContext("A a;"); + verifyGoogleFormat("A a;"); + verifyGoogleFormat("A a;"); } TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {