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 } Release: 3.2/3.3/3.4 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
State-Changed-From-To: open->analyzed State-Changed-Why: yup
From: "Giovanni Bajo" <giovannibajo@libero.it> To: <loewis@informatik.hu-berlin.de>, <gcc-gnats@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>, <nobody@gcc.gnu.org>, <gcc-prs@gcc.gnu.org> Cc: Subject: Re: c++/5388: [3.3/3.4 regression] Incorrect message "operands to ?: have different types" Date: Thu, 1 May 2003 17:33:46 +0200 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5388 I just noted that this is a 3.3/3.4 regression and marked it as such. Giovanni Bajo
Responsible-Changed-From-To: unassigned->jason Responsible-Changed-Why: mine
From: jason@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/5388 Date: 15 May 2003 22:25:55 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: jason@gcc.gnu.org 2003-05-15 22:25:55 Modified files: gcc/cp : ChangeLog cp-tree.h call.c parser.c Log message: PR c++/5388 * call.c (conditional_conversion): Don't consider implicit conversions if T2 is a base of T1. * cp-tree.h (DERIVED_FROM_P, UNIQUELY_DERIVED_FROM_P): Make boolean. (ACCESSIBLY_UNIQUELY_DERIVED_P, PUBLICLY_UNIQUELY_DERIVED_P): Likewise. * parser.c (cp_parser_primary_expression): Convert a static data member from reference. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3380&r2=1.3381 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.845&r2=1.846 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.385&r2=1.386 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.61&r2=1.62
From: jason@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/5388 Date: 15 May 2003 22:26:33 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: jason@gcc.gnu.org 2003-05-15 22:26:33 Modified files: gcc/cp : call.c cp-tree.h pt.c ChangeLog Log message: PR c++/5388 * call.c (conditional_conversion): Don't consider implicit conversions if T2 is a base of T1. * cp-tree.h (DERIVED_FROM_P, UNIQUELY_DERIVED_FROM_P): Make boolean. (ACCESSIBLY_UNIQUELY_DERIVED_P, PUBLICLY_UNIQUELY_DERIVED_P): Likewise. PR c++/10661 * pt.c (instantiate_class_template): Also instantiate our enclosing class. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.341.2.19&r2=1.341.2.20 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.776.2.18&r2=1.776.2.19 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.22&r2=1.635.2.23 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.132&r2=1.3076.2.133
State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed for 3.3.1.