public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/5388: <synopsis of the problem (one line)>
@ 2002-01-15  6:16 Martin von Loewis
  0 siblings, 0 replies; only message in thread
From: Martin von Loewis @ 2002-01-15  6:16 UTC (permalink / raw)
  To: gcc-gnats, debian-gcc


>Number:         5388
>Category:       c++
>Synopsis:       <synopsis of the problem (one line)>
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 15 06:16:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Martin v. Loewis <loewis@informatik.hu-berlin.de
>Release:        3.0.3 (Debian testing/unstable)
>Organization:
>Environment:
System: Linux kosh 2.4.13-586-ext3 #1 Die Nov 6 00:09:32 CET 2001 i686 unknown
Architecture: i686

	
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux
>Description:
Compiling the program below gives the message

operands to ?: have different types

I believe that this message is incorrect, according to 5.16/3: One is a
base class of the other, so the resulting type of the expression is A.


#include <stdio.h>

class A {
    public:
        A() {}
        virtual void print() const {
            printf("I'm A\n");
        }
        A& operator=(const A&) {
           printf("A asignment\n"); return *this;
        }

        static const A& Convert(const A&x){
            return x;
        }
};

class B : public A {
    public:
        B() {}
        B(const A&) {
            printf("A to B conversion\n");
        }
        B& operator=(const B&) {
           printf("B asignment\n"); return *this;
        }
        virtual void print() const {
            printf("I'm B\n");
        }
        static const B& Convert(const B&x){
            return x;
        }
};

A& getA() {
    static A *a = new A;
    return *a;
}

B& getB() {
    static B *b = new B;
    return *b;
}


main() {
    bool b = true;
    getA() = b ? A() : B(); // correct
}
>How-To-Repeat:
	
>Fix:

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-01-15 14:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-15  6:16 c++/5388: <synopsis of the problem (one line)> Martin von Loewis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).