diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1722,6 +1722,11 @@ return false; } + // This is the default value of a non-template type parameter, so treat + // it as an expression. + if (Contexts.back().ContextKind == tok::less) + return true; + Tok = Tok->MatchingParen; if (!Tok) return false; diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -253,6 +253,14 @@ "};"); ASSERT_EQ(Tokens.size(), 30u) << Tokens; EXPECT_TOKEN(Tokens[14], tok::ampamp, TT_BinaryOperator); + + Tokens = annotate("template struct S {};"); + ASSERT_EQ(Tokens.size(), 15u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::ampamp, TT_BinaryOperator); + + Tokens = annotate("template struct S {};"); + ASSERT_EQ(Tokens.size(), 18u) << Tokens; + EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator); } TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {