[llvm-dev] 'cl::opt' and range checking

Zachary Turner via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 3 20:55:25 PDT 2017


I don't think this is currently supported by `cl::opt`, but you can
probably write your own adapter class so that you could write
`cl::opt<cl::range<int,3,7>>`.

You'd just need to write a parser for `cl::range` and do the checking in
there.  Seems like a useful patch, I've needed this from time to time
myself.

On Tue, Oct 3, 2017 at 6:24 AM ORiordan, Martin via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi LLVM-Devs,
>
>
>
> The LLVM ‘cl::opt’ templates are really useful, and provide a lot of
> flexibility.  But I don’t see any support for ranged options.  What I would
> like is to have an option which is an integer type, and to restrict the set
> of values provided to a simple upper and lower bound, for example between
> 10 and 2000.
>
>
>
> Is there a way of expressing this with the ‘cl::opt’ templates, or do I
> have to explicitly range check the values in my own code and issue a
> diagnostic or clamp as appropriate?
>
>
>
> Thanks,
>
>
>
>             MartinO
>
>
>
> --------------------------------------------------------------
> Intel Research and Development Ireland Limited
> Registered in Ireland
> Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
> Registered Number: 308263
>
> This e-mail and any attachments may contain confidential material for the
> sole use of the intended recipient(s). Any review or distribution by others
> is strictly prohibited. If you are not the intended recipient, please
> contact the sender and delete all copies.
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171004/3ddad7e1/attachment.html>


More information about the llvm-dev mailing list