This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8374: ?: operator and derived classes
- From: ossi at kde dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 28 Oct 2002 01:06:51 -0000
- Subject: c++/8374: ?: operator and derived classes
- Reply-to: ossi at kde dot org
>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: