0

While writing a clang plugin, I noticed that objects of type llvm::cl::opt<T> are not convertible to std::any, i.e. the following snippet does not compile:

#include <any> #include <string> #include "llvm/Support/CommandLine.h" int main() { llvm::cl::opt<std::string> opt("o"); std::any opt_any = opt; // doesn't work! } 

I would like to know both why this isn't possible in this specific instance and what criteria a type has to fullfill in general in order to be convertible to std::any.

4
  • 6
    please include the error message in the question Commented Jul 8, 2020 at 13:56
  • @idclev463035818: That depends on the compiler and is not very insightful for both gcc and clang. Commented Jul 8, 2020 at 14:04
  • 3
    somewhere hidden, the error message just says the same as the answer. Maybe you cannot read it, but perhaps others can and also others might get the similar error so including the error message would make the question more useful for future readers Commented Jul 8, 2020 at 14:05
  • note to what @ idclev said: because then others pass-in error in search engine, it would link to here. Commented Jul 8, 2020 at 15:13

1 Answer 1

5

llvm::cl::opt is not copyable. Both the copy constrcutor and copy assignment operator are marked as delete.

std::any requires that in construction and assignment that the type be copyable.


You could use a std::unique_ptr<llvm::cl::opt<std::string>> or std::shared_ptr<llvm::cl::opt<std::string>> or even a std::reference_wrapper depending on how you want to handle the lifetime of the object.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.