>Submitter-Id:  net
>Originator:    Martin v. Loewis <[EMAIL PROTECTED]
>Organization:  
>Confidential:  no
>Synopsis:      
>Severity:      serious
>Priority:      medium
>Category:      c++
>Class:         rejects-legal
>Release:       3.0.3 (Debian testing/unstable)
>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:


Reply via email to