[cfe-dev] constexpr with builtin

Richard Smith richard at metafoo.co.uk
Mon Sep 9 21:40:26 PDT 2013


On 9 Sep 2013 20:40, "fil" <fil at pobox.com> wrote:
>
> Richard Smith wrote
> >> 1. know of a way to use builtin functions (like clz) in a constexpr
> >> context?
> >> I am figuring I need to re-implement it, no way to use the CPU
> >> instruction
> >> at compile time (?)
> >>
> >
> > __builtin_clz works in constant expressions in recent Clang revisions.
You
> > only need to upgrade =)
>
> Right.. good to know. Did this change come in 3.3 or very latest SVN?

Sorry, I don't remember. Maybe someone with 3.3 can test this for you. I
think it was more recently than that, though.

> Richard Smith wrote
> > 2. why does a branch allow it to be compiled? I would have thought that
> > the
> >> compiler would inspect both branches and insist they both be a const
> >> friendly.
> >
> > The compiler does inspect both branches, but it only insists that *one*
of
> > them is constexpr-friendly. It's valid for a ?: to select between a
> > potentially-constant expression and a never-constant expression within a
> > constexpr function.
>
> Gotcha. I expected it to be a bit more draconian on guaranteeing constexpr
> in all branches. Thx for the follow up.
>
> Regards, Fil.
>
>
>
>
> --
> View this message in context:
http://clang-developers.42468.n3.nabble.com/constexpr-with-builtin-tp4034336p4034358.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130909/f11816eb/attachment.html>


More information about the cfe-dev mailing list