This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/31780] [4.2/4.3 regression] ICE with incompatible types for ?: with "complex type" conversion
- From: "mmitchel at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Jul 2007 22:21:27 -0000
- Subject: [Bug c++/31780] [4.2/4.3 regression] ICE with incompatible types for ?: with "complex type" conversion
- References: <bug-31780-1771@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #7 from mmitchel at gcc dot gnu dot org 2007-07-07 22:21 -------
I've attached a patch which fixes this bug in an obvious way.
Since complex types are arithmetic types in GNU C++, we should allow standard
conversions to them from integers, just as we do for all other arithmetic
types.
However, this runs into problems with libstdc++. In particular,
std::complex<double> has a constructor from double and also a constructor from
__complex__ double. Making the change in this patch makes that conversion
ambiguous because now "std::complex<double>(1)" can go via either the
"__complex__ double" constructor or the plain "double" constructor.
I'm pretty sure that we did indeed discuss this at some point in the past,
although I couldn't find a link and I don't remember what we decided, if
anything.
The easiest way to fix this is probably to add more constructors to
std::complex<double> to match all of the arithmetic types directly, e.g., add
"std::complex<double>::complex(int, int = 0)". Then, that will be the best
match.
I think we need input from the libstdc++ maintainers before trying to do
anything in the front end. Paolo?
--
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pcarlini at suse dot de
Status|ASSIGNED |WAITING
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31780