[Bug c++/31780] [4.2/4.3 regression] ICE with incompatible types for ?: with "complex type" conversion
mmitchel at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sat Jul 7 22:21:00 GMT 2007
------- 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
More information about the Gcc-bugs
mailing list