This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: :? ??
- From: Joe Buck <Joe dot Buck at synopsys dot com>
- To: snowwolf at one2one-networks dot com (Allan Sandfeld Jensen)
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 19 Mar 2002 09:19:24 -0800 (PST)
- Subject: Re: :? ??
> Hi
> I have just been fixing several files in KDE 3.0 so they compile using Sun's
> native compiler. The most frequent fix I had to make was the following case:
>
> for some QString a:
> QString b = (exp) ? "xyz" : a;
>
> Now the sun compiler insisted the two types in ?: needs to be identical. Now
> I am wondering what on earth gcc is doing?
If Sun issues a message claiming that the types of the second and third
arguments need to be identical, this is wrong.
The ISO C++ standard specifies the behavior of this operation. Without
seeing the set of operations that the QString class declares, I can't tell
if there is a bug or not, or which compiler has the bug.
> Is it doing:
> (exp) ? QString("xyz") : a
> or
> QString(exp ? "xyz" : (const char*)a);
Does QString define an operator const char*() ? The std::string class
avoids this problem by making the user invoke a specific function to
convert to const char*.
- References:
- :? ??
- From: Allan Sandfeld Jensen