This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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*.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]