[PATCH] D115433: [CommandLine] Reset option to its default if its Default field is undefined
Yevgeny Rouban via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 27 05:58:45 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7fb39fb6d666: [Support] Reset option to its default if its Default field is undefined (authored by yrouban).
Changed prior to commit:
https://reviews.llvm.org/D115433?vs=393067&id=411670#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115433/new/
https://reviews.llvm.org/D115433
Files:
llvm/include/llvm/Support/CommandLine.h
llvm/unittests/Support/CommandLineTest.cpp
Index: llvm/unittests/Support/CommandLineTest.cpp
===================================================================
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -1934,8 +1934,9 @@
TEST(CommandLineTest, ResetAllOptionOccurrences) {
cl::ResetCommandLineParser();
- // -option -enableA -enableC [sink] input [args]
+ // -option -str -enableA -enableC [sink] input [args]
StackOption<bool> Option("option");
+ StackOption<std::string> Str("str");
enum Vals { ValA, ValB, ValC };
StackOption<Vals, cl::bits<Vals>> Bits(
cl::values(clEnumValN(ValA, "enableA", "Enable A"),
@@ -1945,15 +1946,16 @@
StackOption<std::string> Input(cl::Positional);
StackOption<std::string, cl::list<std::string>> ExtraArgs(cl::ConsumeAfter);
- const char *Args[] = {"prog", "-option", "-enableA", "-enableC",
- "-unknown", "input", "-arg"};
+ const char *Args[] = {"prog", "-option", "-str=STR", "-enableA",
+ "-enableC", "-unknown", "input", "-arg"};
std::string Errs;
raw_string_ostream OS(Errs);
- EXPECT_TRUE(cl::ParseCommandLineOptions(7, Args, StringRef(), &OS));
+ EXPECT_TRUE(cl::ParseCommandLineOptions(8, Args, StringRef(), &OS));
EXPECT_TRUE(OS.str().empty());
EXPECT_TRUE(Option);
+ EXPECT_EQ("STR", Str);
EXPECT_EQ((1u << ValA) | (1u << ValC), Bits.getBits());
EXPECT_EQ(1u, Sink.size());
EXPECT_EQ("-unknown", Sink[0]);
@@ -1963,6 +1965,7 @@
cl::ResetAllOptionOccurrences();
EXPECT_FALSE(Option);
+ EXPECT_EQ("", Str);
EXPECT_EQ(0u, Bits.getBits());
EXPECT_EQ(0u, Sink.size());
EXPECT_EQ(0, Input.getNumOccurrences());
Index: llvm/include/llvm/Support/CommandLine.h
===================================================================
--- llvm/include/llvm/Support/CommandLine.h
+++ llvm/include/llvm/Support/CommandLine.h
@@ -1436,6 +1436,8 @@
const OptionValue<DataType> &V = this->getDefault();
if (V.hasValue())
this->setValue(V.getValue());
+ else
+ this->setValue(T());
}
template <class T,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115433.411670.patch
Type: text/x-patch
Size: 2112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220227/143aedc8/attachment.bin>
More information about the llvm-commits
mailing list