]> granicus.if.org Git - clang/commitdiff
Correctly detect colon in bit fields. Fixes PR17333.
authorAlexander Kornienko <alexfh@google.com>
Thu, 10 Oct 2013 13:36:20 +0000 (13:36 +0000)
committerAlexander Kornienko <alexfh@google.com>
Thu, 10 Oct 2013 13:36:20 +0000 (13:36 +0000)
Summary: Colon was incorrectly detected as a start of inheritance list. Fixed.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D1884

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192349 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/FormatToken.h
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index c02ac6357a9b90e3148a0970a2971dfbc9bd7a6f..2541c782aca820fb672cb43761d61eca7897c6b6 100644 (file)
@@ -26,6 +26,7 @@ namespace format {
 
 enum TokenType {
   TT_BinaryOperator,
+  TT_BitFieldColon,
   TT_BlockComment,
   TT_CastRParen,
   TT_ConditionalExpr,
index 823235e602c03ffb5b5e1d21ed91c06eb0fda3a7..87549895b1c5578e97fbfcfe994183b33f1c4581 100644 (file)
@@ -328,13 +328,15 @@ private:
         Tok->Previous->Type = TT_ObjCSelectorName;
         if (Tok->Previous->ColumnWidth >
             Contexts.back().LongestObjCSelectorName) {
-          Contexts.back().LongestObjCSelectorName =
-              Tok->Previous->ColumnWidth;
+          Contexts.back().LongestObjCSelectorName = Tok->Previous->ColumnWidth;
         }
         if (Contexts.back().FirstObjCSelectorName == NULL)
           Contexts.back().FirstObjCSelectorName = Tok->Previous;
       } else if (Contexts.back().ColonIsForRangeExpr) {
         Tok->Type = TT_RangeBasedForLoopColon;
+      } else if (CurrentToken != NULL &&
+                 CurrentToken->is(tok::numeric_constant)) {
+        Tok->Type = TT_BitFieldColon;
       } else if (Contexts.size() == 1 && Line.First->isNot(tok::kw_enum)) {
         Tok->Type = TT_InheritanceColon;
       } else if (Contexts.back().ContextKind == tok::l_paren) {
@@ -1370,8 +1372,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
              !Style.ConstructorInitializerAllOnOneLineOrOnePerLine) {
     return true;
   } else if (Right.Previous->BlockKind == BK_Block &&
-             Right.Previous->isNot(tok::r_brace) &&
-             Right.isNot(tok::r_brace)) {
+             Right.Previous->isNot(tok::r_brace) && Right.isNot(tok::r_brace)) {
     return true;
   } else if (Right.is(tok::l_brace) && (Right.BlockKind == BK_Block)) {
     return Style.BreakBeforeBraces == FormatStyle::BS_Allman;
index 10d7413d42271d34a965d243ba43c602b5c03a92..c77616c96b49ccab1fb07ca80daad2f36777a8ae 100644 (file)
@@ -1635,6 +1635,10 @@ TEST_F(FormatTest, FormatsBitfields) {
                "  unsigned sClass : 8;\n"
                "  unsigned ValueKind : 2;\n"
                "};");
+  verifyFormat("struct A {\n"
+               "  int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa : 1,\n"
+               "      bbbbbbbbbbbbbbbbbbbbbbbbb;\n"
+               "};");
 }
 
 TEST_F(FormatTest, FormatsNamespaces) {