[PATCH] D61222: [clang-format] Fix bug in determineTokenType() for TT_StartOfName

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 27 02:10:27 PDT 2019


owenpan created this revision.
owenpan added reviewers: klimek, MyDeveloperDay, sammccall, krasimir, djasper.
owenpan added a project: clang.
Herald added a subscriber: cfe-commits.

This patch fixes PR37175 <https://bugs.llvm.org/show_bug.cgi?id=37175>.


Repository:
  rC Clang

https://reviews.llvm.org/D61222

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10575,6 +10575,13 @@
                "  unsigned c;\n"
                "}",
                Alignment);
+
+  // See PR37175
+  FormatStyle Style = getMozillaStyle();
+  Style.AlignConsecutiveDeclarations = true;
+  EXPECT_EQ("DECOR1 DECOR2 uint32_t\n"
+            "f1(int arg1, int arg2);",
+            format("DECOR1 DECOR2 uint32_t f1 (int arg1, int arg2);", Style));
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1350,8 +1350,14 @@
       Current.Type = TT_BinaryOperator;
     } else if (isStartOfName(Current) &&
                (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
-      Contexts.back().FirstStartOfName = &Current;
-      Current.Type = TT_StartOfName;
+      const FormatToken *Next = Current.Next;
+      bool NonMacroIdentifier =
+          Next && Next->Tok.getIdentifierInfo() &&
+          Next->TokenText != Next->TokenText.upper();
+      if (!NonMacroIdentifier) {
+        Contexts.back().FirstStartOfName = &Current;
+        Current.Type = TT_StartOfName;
+      }
     } else if (Current.is(tok::semi)) {
       // Reset FirstStartOfName after finding a semicolon so that a for loop
       // with multiple increment statements is not confused with a for loop


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61222.196953.patch
Type: text/x-patch
Size: 1603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190427/205d5023/attachment.bin>


More information about the cfe-commits mailing list