[PATCH] D116726: [clang-format] Fix a crash (assertion) in qualifier alignment when matching template closer is null

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 6 00:24:45 PST 2022


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: owenpan, curdeius, HazardyKnusperkeks, JohelEGP.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.

https://github.com/llvm/llvm-project/issues/53008

  template <class Id> using A = quantity /**/<kind<Id>, 1>;

the presence of the comment between identifier and template opener seems to be causing the qualifier alignment to fail


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116726

Files:
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/unittests/Format/QualifierFixerTest.cpp


Index: clang/unittests/Format/QualifierFixerTest.cpp
===================================================================
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -818,5 +818,18 @@
   EXPECT_EQ(ReplacementCount, 0);
 }
 
+TEST_F(QualifierFixerTest, QualifierTemplates) {
+
+  FormatStyle Style = getLLVMStyle();
+  Style.QualifierAlignment = FormatStyle::QAS_Custom;
+  Style.QualifierOrder = {"static", "const", "type"};
+
+  ReplacementCount = 0;
+  EXPECT_EQ(ReplacementCount, 0);
+  verifyFormat("template <class Id> using A = quantity /**/<kind<Id>, 1>;",
+               Style);
+  EXPECT_EQ(ReplacementCount, 0);
+}
+
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===================================================================
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -334,7 +334,8 @@
         Next->Previous->startsSequence(tok::identifier, TT_TemplateOpener)) {
       // Read from to the end of the TemplateOpener to
       // TemplateCloser const ArrayRef<int> a; const ArrayRef<int> &a;
-      assert(Next->MatchingParen && "Missing template closer");
+      if (!Next->MatchingParen)
+        return Next;
       Next = Next->MatchingParen->Next;
 
       // Move to the end of any template class members e.g.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116726.397803.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220106/dd5fedb6/attachment-0001.bin>


More information about the cfe-commits mailing list