[PATCH] D61972: [CommandLine] Don't allow duplicate categories.

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 09:23:27 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL360913: [CommandLine] Don't allow duplicate categories. (authored by dhinton, committed by ).
Herald added a subscriber: kristina.

Changed prior to commit:
  https://reviews.llvm.org/D61972?vs=199735&id=199847#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61972/new/

https://reviews.llvm.org/D61972

Files:
  llvm/trunk/lib/Support/CommandLine.cpp
  llvm/trunk/unittests/Support/CommandLineTest.cpp


Index: llvm/trunk/unittests/Support/CommandLineTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/CommandLineTest.cpp
+++ llvm/trunk/unittests/Support/CommandLineTest.cpp
@@ -170,8 +170,12 @@
 
 TEST(CommandLineTest, UseMultipleCategories) {
   StackOption<int> TestOption2("test-option2", cl::cat(TestCategory),
+                               cl::cat(cl::GeneralCategory),
                                cl::cat(cl::GeneralCategory));
 
+  // Make sure cl::GeneralCategory wasn't added twice.
+  ASSERT_EQ(TestOption2.Categories.size(), 2U);
+
   ASSERT_NE(TestOption2.Categories.end(),
             find_if(TestOption2.Categories,
                          [&](const llvm::cl::OptionCategory *Cat) {
Index: llvm/trunk/lib/Support/CommandLine.cpp
===================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp
+++ llvm/trunk/lib/Support/CommandLine.cpp
@@ -450,7 +450,7 @@
   // must be explicitly added if you want multiple categories that include it.
   if (&C != &GeneralCategory && Categories[0] == &GeneralCategory)
     Categories[0] = &C;
-  else
+  else if (find(Categories, &C) == Categories.end())
     Categories.push_back(&C);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61972.199847.patch
Type: text/x-patch
Size: 1254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/94ed21e7/attachment.bin>


More information about the llvm-commits mailing list