This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] c++0x common_type patch
- From: Douglas Gregor <dgregor at osl dot iu dot edu>
- To: Chris Fairles <chris dot fairles at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org, libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 07 Jul 2008 21:51:03 -0400
- Subject: Re: [v3] c++0x common_type patch
- References: <fac6bb500807031415l72b6c934xa50025aa42ab05a2@mail.gmail.com>
- Reply-to: dgregor at osl dot iu dot edu
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