www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



c++ - Compiler doesn't do type conversion of operator?: operands

↑ ↓ ← Vaclav Slavik <vslavik fastmail.fm> writes:
Hi,

here's another bug affecting wxWidgets development version: if the types of
operator?:'s operands differ, the compiler doesn't try to convert them to a
common type. Interestingly enough, it *does* do conversion in some cases (i.e.
is already better than BCC5.5, which never converts), but not in others.
Again, this is with the latest stable as well as 8.50 beta versions.

The following code demonstrates it:
--------------
struct wxCStrData
{
    wxCStrData(char *buf) {}
    operator const char*() const { return "x"; }
};

void foo(int n)
{
    wxCStrData c("x");
    const char *x = (n==1) ? c : "bar";
}
--------------

The error given by DMC ("dmc test.cpp") is:

    const char *x = (n==1) ? c : "bar";
                                      ^
dmc_ternary_operator.cpp(10) : Error: illegal operand types
Had: wxCStrData
and: char const *
--- errorlevel 1

The code compiles with all other compilers supported by wx (except BCC5.5,
which has really touchy operator?:) as well as Comeau in strict mode.

Regards,
Vaclav
Mar 16 2007
↑ ↓ → Walter Bright <newshound digitalmars.com> writes:
Thanks for the reports, I'll take care of them.
Mar 18 2007