From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32451 invoked by alias); 1 Apr 2008 15:34:09 -0000 Received: (qmail 32438 invoked by uid 22791); 1 Apr 2008 15:34:08 -0000 X-Spam-Check-By: sourceware.org Received: from qnxmail.qnx.com (HELO nimbus.ott.qnx.com) (209.226.137.76) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 01 Apr 2008 15:33:40 +0000 Received: by nimbus.ott.qnx.com with Internet Mail Service (5.5.2653.19) id <2BHW3DZR>; Tue, 1 Apr 2008 11:33:37 -0400 Message-ID: <47F255CC.4000704@qnx.com> From: Aleksandar Ristovski To: Daniel Jacobowitz Cc: gdb-patches@sourceware.org Subject: Re: [patch] fix for c++/2416 Date: Tue, 01 Apr 2008 16:26:00 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) user-agent: Content-Type: text/plain; charset="iso-8859-1" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-04/txt/msg00021.txt.bz2 Daniel Jacobowitz wrote: > On Thu, Feb 28, 2008 at 11:45:07PM -0500, Aleksandar Ristovski wrote: >> Allright, then how about this, yet newer and yet more revisited diff? I >> removed changes to eval.c and let it simply call value_cast as it used to. >> Now value_cast knows how to handle references. > > We were converging on a fix and then there's a whole different patch > to look at... sorry I couldn't make time until now. > >> @@ -257,6 +290,7 @@ value_cast_pointers (struct type *type, >> return arg2; >> } >> >> + >> /* Cast value ARG2 to type TYPE and return as a value. >> More general than a C cast: accepts any two types of the same length, >> and if ARG2 is an lvalue it can be cast into anything at all. */ > > Please drop the whitespace change. > >> @@ -275,6 +309,26 @@ value_cast (struct type *type, struct va >> if (value_type (arg2) == type) >> return arg2; >> >> + code1 = TYPE_CODE (check_typedef (type)); >> + >> + /* Check if we are casting struct reference to struct reference. */ >> + if (code1 == TYPE_CODE_REF) >> + { >> + /* We dereference type; then we recurse and finally >> + we generate value of the given reference. Nothing wrong with >> + that. */ >> + struct type *t1 = check_typedef (type); >> + struct type *dereftype = check_typedef (TYPE_TARGET_TYPE (t1)); >> + struct value *val = value_cast (dereftype, arg2); >> + return value_ref (val); >> + } > > This allows things like "(int&) int_var", by automatically creating > references. Should we really do that? > I believe we should. Here is a dummy c++ program where this is done explicitly: #include using namespace std; int main () { int a = 42; int &refa = (int &)a; // cast not needed, yet compiler doesn't complain. cout << refa << endl; return 0; }