This is the mail archive of the gcc-bugs@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]

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


>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:


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