[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:25:21 PDT 2019
hintonda updated this revision to Diff 199730.
hintonda added a comment.
Herald added a subscriber: mgorny.
- Used find instead of find_if.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61972/new/
https://reviews.llvm.org/D61972
Files:
llvm/examples/CMakeLists.txt
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);
}
Index: llvm/examples/CMakeLists.txt
===================================================================
--- llvm/examples/CMakeLists.txt
+++ llvm/examples/CMakeLists.txt
@@ -1,4 +1,5 @@
add_subdirectory(BrainF)
+add_subdirectory(CommandLine)
add_subdirectory(Fibonacci)
add_subdirectory(HowToUseJIT)
add_subdirectory(Kaleidoscope)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61972.199730.patch
Type: text/x-patch
Size: 1553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/aad882ef/attachment.bin>
More information about the llvm-commits
mailing list