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

Don Hinton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 20:42:32 PDT 2019


hintonda updated this revision to Diff 199735.
hintonda added a comment.

- Remove file erroneously included in last upload.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61972

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


Index: llvm/unittests/Support/CommandLineTest.cpp
===================================================================
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/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/lib/Support/CommandLine.cpp
===================================================================
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/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.199735.patch
Type: text/x-patch
Size: 1218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/0dbd2be6/attachment.bin>


More information about the llvm-commits mailing list