From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28632 invoked by alias); 21 Feb 2013 19:30:36 -0000 Received: (qmail 28624 invoked by uid 22791); 21 Feb 2013 19:30:35 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 Feb 2013 19:30:31 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1LJUNix002291 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 21 Feb 2013 14:30:31 -0500 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1LJUEUN020795 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 21 Feb 2013 14:30:16 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Subject: RFC: fix PR c++/15116 Date: Thu, 21 Feb 2013 19:30:00 -0000 Message-ID: <87ppztbh2x.fsf@fleche.redhat.com> MIME-Version: 1.0 Content-Type: text/plain 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: 2013-02/txt/msg00567.txt.bz2 This fixes PR c++/15116. The bug is that overloading doesn't work if one of the arguments has function type. I fixed this by updating types_equal to account for this situation. This allows rank_one_type to work properly. A couple notes on this. First, types_equal is fairly primitive. There is a fuller deep-comparison approach in py-type.c. However, that may be overkill here -- and actually seems like it could break overload resolution (see the gross integer_types_same_name_p). Second, overload resolution can actually do a kind of second overload resolution, according to the standard. This is well-formed: int f(int x) { return x; } double f(double x) { return x; } int overload(int x, int (*f)(int)) { return f(x); } int main() { return overload(0, f); } ... and here we would have to do overload resolution on the argument 'f'. I will file a separate bug for this. Built and regtested on x86-64 Fedora 16. New test case included. Tom PR c++/15116: * gdbtypes.c (types_equal): Handle TYPE_CODE_FUNC. * gdb.cp/overload.cc (intintfunc): New. * gdb.cp/overload.exp: Add regression test. diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 12730d7..a1c4018 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2456,6 +2456,25 @@ types_equal (struct type *a, struct type *b) if (a == b) return 1; + /* Two function types are equal if their argument and return types + are equal. */ + if (TYPE_CODE (a) == TYPE_CODE_FUNC) + { + int i; + + if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b)) + return 0; + + if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b))) + return 0; + + for (i = 0; i < TYPE_NFIELDS (a); ++i) + if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i))) + return 0; + + return 1; + } + return 0; } diff --git a/gdb/testsuite/gdb.cp/overload.cc b/gdb/testsuite/gdb.cp/overload.cc index ba0678f..5c782a4 100644 --- a/gdb/testsuite/gdb.cp/overload.cc +++ b/gdb/testsuite/gdb.cp/overload.cc @@ -97,6 +97,8 @@ class D: C {}; int bar (A) { return 11; } int bar (B) { return 22; } +int intintfunc (int x) { return x; } + int main () { char arg2 = 2; diff --git a/gdb/testsuite/gdb.cp/overload.exp b/gdb/testsuite/gdb.cp/overload.exp index 3ebc642..9d49516 100644 --- a/gdb/testsuite/gdb.cp/overload.exp +++ b/gdb/testsuite/gdb.cp/overload.exp @@ -139,6 +139,9 @@ gdb_test "print foo_instance3" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\ gdb_test "print foo_instance1.overloadargs(1)" "\\$\[0-9\]+ = 1" \ "print call overloaded func 1 arg" +# Regression test for overloading with function pointer type. +gdb_test "print foo_instance1.overloadfnarg(23, intintfunc)" " = 23" + # If GDB fails to restore the selected frame properly after the # inferior function call above (see GDB PR 1155 for an explanation of # why this might happen), all the subsequent tests will fail. We