From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8395 invoked by alias); 5 Aug 2009 10:03:50 -0000 Received: (qmail 2540 invoked by uid 48); 5 Aug 2009 10:03:34 -0000 Date: Wed, 05 Aug 2009 10:03:00 -0000 Message-ID: <20090805100334.2539.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/13979] Error message about no matching function for call with derived class arguments could be improved In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "jwakely dot gcc at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-08/txt/msg00513.txt.bz2 ------- Comment #9 from jwakely dot gcc at gmail dot com 2009-08-05 10:03 ------- This example has four slightly different errors: struct B {}; struct D : B {}; struct X {}; int foo(B*&); int i = foo( (B*)0 ); int j = foo( (D*)0 ); D* pd = 0; int k = foo( pd ); X* px = 0; int l = foo( px ); GCC 4.4.1 gives: pr13979.cc:8:20: error: invalid initialization of non-const reference of type ‘B*&’ from a temporary of type ‘B*’ pr13979.cc:6:5: error: in passing argument 1 of ‘int foo(B*&)’ pr13979.cc:10:20: error: invalid initialization of non-const reference of type ‘B*&’ from a temporary of type ‘D*’ pr13979.cc:6:5: error: in passing argument 1 of ‘int foo(B*&)’ pr13979.cc:13:17: error: invalid initialization of reference of type ‘B*&’ from expression of type ‘D*’ pr13979.cc:6:5: error: in passing argument 1 of ‘int foo(B*&)’ pr13979.cc:16:17: error: invalid initialization of reference of type ‘B*&’ from expression of type ‘X*’ pr13979.cc:6:5: error: in passing argument 1 of ‘int foo(B*&)’ Comeau gives equivalent errors in all four cases. The only significant difference is that Comeau doesn't mention the types in the first two errors. GCC 2.95.2 is quite different: pr13979.cc:8: initialization of non-const reference type `struct B *&' pr13979.cc:8: from rvalue of type `B *' pr13979.cc:6: in passing argument 1 of `foo(B *&)' pr13979.cc:10: initializing non-const `B *&' with `D *' will use a temporary pr13979.cc:6: in passing argument 1 of `foo(B *&)' pr13979.cc:13: initializing non-const `B *&' with `D *' will use a temporary pr13979.cc:6: in passing argument 1 of `foo(B *&)' pr13979.cc:16: type `B' is not a base type for type `X' pr13979.cc:6: in passing argument 1 of `foo(B *&)' I think the current diagnostics are better than the 2.95 ones. As I said above, "will use a temporary" is misleading. The fourth error saying "is not a base type" may be true, but is also misleading, because it wouldn't compile even if it was a base type. As I said earlier, it might be nice if the third error said e.g. pr13979.cc:13:17: error: invalid initialization of reference of type ‘B*&’ from expression of type ‘D*’ pr13979.cc:6:5: error: in passing argument 1 of ‘int foo(B*&)’ pr13979.cc:13:17: note: conversion from `D*' to `B*' would create a temporary However, (In reply to comment #8) > I don't even know if we have different codepaths for those! if it's not possible then I think the current diagnostics are reasonable, and at least as good as Comeau's. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13979