[llvm-dev] CommandLine -- ResetAllOptionOccurrences with cl::bits -- Bug or by design?

Riyaz Puthiyapurayil via llvm-dev llvm-dev at lists.llvm.org
Sun Mar 21 16:30:00 PDT 2021


I have some unit tests where I want to parse different command lines where some options use cl::bits with an enum type. I want to reset the option occurrences in each unit test and reinvoke the command line parser with a new command line. While ResetAllOptionOccurrences resets every other kind of option, it doesn't do so for cl::bits. Is this by design?

I see setDefaultValue of cl::bits is an empty function. Why doesn't it set the internal bit storage to 0 when ResetAllOptionOccurrences is called? I thought I could instead use an external storage and set that to 0. But that doesn't work either. It results in an error:

unsigned MyOptStorage;
static llvm::cl::bits<MyOpt, unsigned> MyOpts(
....
      llvm::cl::location(MyOptStorage),
...);

include/llvm/Support/CommandLine.h:1723:23: error: reinterpret_cast from 'MyOpt' to 'unsigned int' is not allowed
    unsigned BitPos = reinterpret_cast<unsigned>(V);

where 'MyOpt' is an enum type.

So how does one specify cl::bits with an external storage location if DataType is an enum? There is not much information in Command Line Reference Manual. Note that I used unsigned above just like the excerpt from the manual says:

The cl::bits class is the class used to represent a list of command line options in the form of a bit vector. It is also a templated class which can take up to three arguments:
namespace cl {
  template <class DataType, class Storage = bool,
            class ParserClass = parser<DataType> >
  class bits;
}
This class works the exact same as the cl::list class, except that the second argument must be of type unsigned if external storage is used.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210321/d209aa16/attachment.html>


More information about the llvm-dev mailing list