[clang] 400da11 - [clang-format] Fix braced initializer with templated base class

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 1 13:53:32 PDT 2023


Author: Galen Elias
Date: 2023-08-01T13:53:22-07:00
New Revision: 400da115c58ae19445cfdc871a3f559f160fc5c6

URL: https://github.com/llvm/llvm-project/commit/400da115c58ae19445cfdc871a3f559f160fc5c6
DIFF: https://github.com/llvm/llvm-project/commit/400da115c58ae19445cfdc871a3f559f160fc5c6.diff

LOG: [clang-format] Fix braced initializer with templated base class

Fixes #64134.

Differential Revision: https://reviews.llvm.org/D156705

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index febe43e1ba65f4..5c6e7e2e1194e9 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -581,7 +581,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
           ProbablyBracedList =
               ProbablyBracedList ||
               (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok &&
-               LBraceStack.back().PrevTok->is(tok::identifier));
+               LBraceStack.back().PrevTok->isOneOf(tok::identifier,
+                                                   tok::greater));
 
           ProbablyBracedList =
               ProbablyBracedList ||

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index e512a861dc4e35..ed0c5e64f44743 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13458,6 +13458,8 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   verifyFormat(
       "class A {\n"
       "  A() : a{} {}\n"
+      "  A() : Base<int>{} {}\n"
+      "  A() : Base<Foo<int>>{} {}\n"
       "  A(int b) : b(b) {}\n"
       "  A(int a, int b) : a(a), bs{{bs...}} { f(); }\n"
       "  int a, b;\n"


        


More information about the cfe-commits mailing list