[v3] c++0x common_type patch

Chris Fairles chris.fairles@gmail.com
Tue Jul 8 11:10:00 GMT 2008


On Mon, Jul 7, 2008 at 9:51 PM, Douglas Gregor <dgregor@osl.iu.edu> wrote:
>
> On Thu, 2008-07-03 at 17:15 -0400, Chris Fairles wrote:
>> Patch for common_type. It's using __typeof__ instead of decltype until
>> PR 36628 is resolved. I'm not sure if the test cases are sufficient or
>> if the crazy macro's are allowed to be used in test cases (I didn't
>> see any being used in the other modification type traits).
>
> I'm looking at PR 36628, but the issue is a little deeper that I'd hoped
> for, and I don't have a patch ready yet. However, you can work around
> this bug by replacing this:
>
>  typedef __typeof__(true ? __t() : __u()) type;
>
> with something like:
>
>  bool __true_or_false();
>
>  // later on ...
>
>  typedef decltype(__true_or_false() ? __t() : __u()) type;
>
> Basically, the compiler is optimizing away the conditional before taking
> its decltype (because it knows we'll be taking the left-hand side). So,
> putting in the __true_or_false() suppresses that optimization and gets
> the right answer.
>
> Please make a note in common_type about PR 36628, so that we know to
> remove the hack when it gets fixed in the front end.
>
>  - Doug
>
>

Attached is updated patch.

Cheers,
Chris
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: common_type2.patch.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080708/50471f00/attachment.txt>


More information about the Gcc-patches mailing list