[PATCH] D41674: [Support] CommandLine API -- Allow creating custom parsers for fundamental types

Christoph Kindl via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 2 11:52:57 PST 2018

ckristo created this revision.
ckristo added reviewers: chandlerc, dblaikie.

I lately stumbled upon the bug #25104 <https://bugs.llvm.org/show_bug.cgi?id=25104> while I wanted to create a custom parser for a cl::opt<float> command line option. Since cl::parser<T> implementations were marked final in 3.7, it is no longer possible to derive from them as described in the CommandLine documentation <https://llvm.org/docs/CommandLine.html>. Deriving from cl::basic_parser<T> for fundamental types is not possible either, causing a compile error like

  llvm/include/llvm/Support/CommandLine.h:1109:20: No viable conversion from 'const (anonymous namespace)::CustomParser' to 'const parser<T>'

This small patch allows to derive from cl::basic_parser<T> for fundamental types. Please note that this patch does not allow to build upon existing parsers again (as prev. possible by inheriting from cl::parser<T>), i.e. custom parser for numeric options must reimplement number parsing. This is not ideal, I know, but I do not have an idea how to make this easily possible again without removing final from cl::parser<T>. Any ideas that can be incorporated in this patch are welcome of course :-)

I kindly ask for review.




-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41674.128438.patch
Type: text/x-patch
Size: 11233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180102/508fe001/attachment.bin>

More information about the llvm-commits mailing list