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++/5388: <synopsis of the problem (one line)>



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


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