c++/8374: ?: operator and derived classes

ossi@kde.org ossi@kde.org
Sun Oct 27 22:37:00 GMT 2002


>Number:         8374
>Category:       c++
>Synopsis:       ?: operator and derived classes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 27 17:16:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     ossi@kde.org
>Release:        3.2.1-pre as currently shipped with debian unstable
>Organization:
>Environment:

>Description:
compiling
---------------------
class Base {};
class Derived1 : public Base {};
class Derived2 : public Base {};

int main(int argc, char **argv)
{
  Base *ptr = (argc > 1) ? new Derived1 : new Derived2;
  return 0;
}
-----------------
leads to the output
--------
conditional expression between distinct pointer types `Derived1*' and `Derived2*' lacks a cast
invalid conversion from `void*' to `Base*'
--------
i'm not sure if any standard requires this behaviour, but i consider it nonsense.
the -pedantic switch makes it compile; together with -ansi switch one even does not get flooded wiht related warnings.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list