llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) <details> <summary>Changes</summary> Fix #<!-- -->142050 --- Full diff: https://github.com/llvm/llvm-project/pull/142110.diff 2 Files Affected: - (modified) clang/lib/Format/TokenAnnotator.cpp (+3-1) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+8) ``````````diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 51ececc0c0e81..f8272811bbe6c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1411,7 +1411,9 @@ class AnnotatingParser { assert(Prev); if (Prev->isPointerOrReference()) Prev->setFinalizedType(TT_PointerOrReference); - } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) { + } else if ((CurrentToken && CurrentToken->is(tok::numeric_constant)) || + (Prev && Prev->is(TT_StartOfName) && !Scopes.empty() && + Scopes.back() == ST_Class)) { Tok->setType(TT_BitFieldColon); } else if (Contexts.size() == 1 && !Line.getFirstNonComment()->isOneOf(tok::kw_enum, tok::kw_case, diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index f39468424a393..1a5ed4b9040c2 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -4076,6 +4076,14 @@ TEST_F(TokenAnnotatorTest, EnumColonInTypedef) { EXPECT_TOKEN(Tokens[2], tok::colon, TT_Unknown); // Not TT_InheritanceColon. } +TEST_F(TokenAnnotatorTest, BitFieldColon) { + auto Tokens = annotate("class C {\n" + " int f : SIZE;\n" + "};"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::colon, TT_BitFieldColon); +} + } // namespace } // namespace format } // namespace clang `````````` </details> https://github.com/llvm/llvm-project/pull/142110 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits