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
This patch changes constructor of the non-class specializations to keep the Default field unset (that is None) rather than initialize it with DataType().
do you want me to add a comment?