[Support] Reset option to its default if its Default field is undefined
authorYevgeny Rouban <yrouban@azul.com>
Sun, 27 Feb 2022 12:56:31 +0000 (19:56 +0700)
committerYevgeny Rouban <yrouban@azul.com>
Sun, 27 Feb 2022 13:57:28 +0000 (20:57 +0700)
commit7fb39fb6d6665cd469557b43eb205cc32b0a7ac3
tree2719b1f424e6ba37057086df87fb28d1e8ae7740
parent9bc866cc6f4fa01186e5ec8306d6b542962b27e9
[Support] Reset option to its default if its Default field is undefined

opt::setDefaultImpl() is changed to set the option value to the option
type's default if the Default field is not set. This results in option
value reset by Option::reset() or ResetAllOptionOccurrences() even if
the cl::init() is not specified.

Example:
  StackOption<std::string> Str("str"); // No cl::init().
  Str = "some value";
  cl::ResetAllOptionOccurrences();
  EXPECT_EQ("", Str); // The Str is reset.

Reviewed By: lattner
Differential Revision: https://reviews.llvm.org/D115433
llvm/include/llvm/Support/CommandLine.h
llvm/unittests/Support/CommandLineTest.cpp