[PATCH] D114645: [CommandLine] Keep option default value unset if no cl::init() is used

Yevgeny Rouban via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 26 08:12:39 PST 2021


yrouban created this revision.
yrouban added reviewers: hintonda, greened, lattner, beanz.
Herald added a subscriber: dexonsmith.
yrouban requested review of this revision.
Herald added a project: LLVM.

Current declaration of cl::opt is incoherent between class and non-class specializations of the //opt_storage// template. There is an inconsistency in the initialization of the //Default// field: for inClass instances the default constructor is used - it sets the Optional //Default// field to //None//; though for non-inClass instances the //Default// field is set to the type's default value. For non-inClass instances it is impossible to know if the option is defined with cl::init() initializer or not:

  cl::opt<int> i1("option-i1");
  cl::opt<int> i2("option-i2", cl::init(0));
  cl::opt<std::string> s1("option-s1");
  cl::opt<std::string> s2("option-s2", cl::init(""));
  
  assert(s1.Default.hasValue() != s2.Default.hasValue()); // Ok
  assert(i1.Default.hasValue() != i2.Default.hasValue()); // Fails


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114645

Files:
  llvm/include/llvm/Support/CommandLine.h
  llvm/unittests/Support/CommandLineTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114645.390059.patch
Type: text/x-patch
Size: 3875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211126/263ddc4b/attachment.bin>


More information about the llvm-commits mailing list