From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31041 invoked by alias); 5 Oct 2010 19:06:38 -0000 Received: (qmail 31028 invoked by uid 22791); 5 Oct 2010 19:06:36 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD 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; Tue, 05 Oct 2010 19:06:29 +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.13.8/8.13.8) with ESMTP id o95J6Sxo013335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Oct 2010 15:06:28 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o95J6Q4j011484 for ; Tue, 5 Oct 2010 15:06:27 -0400 Received: from [10.15.16.129] (dhcp-10-15-16-129.yyz.redhat.com [10.15.16.129]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o95J6PRd007055 for ; Tue, 5 Oct 2010 15:06:25 -0400 Message-ID: <4CAB7733.6020105@redhat.com> Date: Tue, 05 Oct 2010 19:06:00 -0000 From: sami wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100806 Fedora/3.1.2-1.fc13 Lightning/1.0b2pre Thunderbird/3.1.2 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [patch] Overload resolution test case Content-Type: multipart/mixed; boundary="------------050405080102060704040304" 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: 2010-10/txt/msg00051.txt.bz2 This is a multi-part message in MIME format. --------------050405080102060704040304 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 182 After consulting the C++ spec, I have created a test case for untested and unimplemented overload resolution scenarios. The test case has been marked with the appropriate kfails. --------------050405080102060704040304 Content-Type: text/x-patch; name="overload_test.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="overload_test.patch" Content-length: 7923 Test case for unimplemented overload cases. 2010-10-05 Sami Wagiaalla * gdb.cp/oranking.exp: New test. * gdb.cp/oranking.cc: New test program. diff --git a/gdb/testsuite/gdb.cp/oranking.cc b/gdb/testsuite/gdb.cp/oranking.cc new file mode 100644 index 0000000..69e0bed --- /dev/null +++ b/gdb/testsuite/gdb.cp/oranking.cc @@ -0,0 +1,203 @@ + +/* 1. A standard covnersion sequence is better than a user-defined sequence + which is better than an elipses conversion sequence. */ + +class A{}; +class B: public A {public: operator int (){ return 1;}}; + +// standard vs user-defined +int foo0 (int) { return 10; } +int foo1 (int) { return 11; } // B -> int : user defined +int foo1 (A) { return 12; } // B -> A : standard +int test1 () { + B b; + return foo1(b); // 12 +} + +// user-defined vs ellipsis +int foo2 (int) { return 13;} // B -> int : user defined +int foo2 (...) { return 14;} // B -> ... : ellipsis +int test2(){ + B b; + return foo2(b); // 13 +} + +/* 2. Standard Conversion squence S1 is better than standard Conversion + S2 if: */ + +// - S1 has a better rank than S2 +// see overload.exp for more comprehensive testing of this. +int foo3 (double) { return 21; } // float->double is 'promotion rank' +int foo3 (int) { return 22; } // float->int is 'conversion rank' +int test3(){ + return foo3 (1.0f); // 21 +} + +// - S1 and S2 are both 'qualification conversions' but S1 cv-qualification +// is a subset of S2 cv-qualification. +int foo4 (const volatile int*) { return 23; } +int foo4 ( volatile int*) { return 24; } +int test4 () { + volatile int a = 5; + return foo4(&a); // 24 +} + +// - S1 and S2 have the same rank but: +// - S2 is a conversion of pointer or memeber-pointer to bool +int foo5 (bool) { return 25; } +int foo5 (void*) { return 26; } +int test5 () { + char *a; + return foo5(a); // 26 +} + +// - Class B publicly extends class A and S1 is a conversion of +// B* to A* and S2 is a conversion B* to void* +int foo6 (void*) { return 27; } +int foo6 (A*) { return 28; } +int test6 () { + B *bp; + return foo6(bp); // 28 +} + +// - Class C publicly extends Class B which publicly extends +// class A and S1 is a conversion of C* to B* and S2 is a +// conversion C* to A*. +class C: public B {}; +int foo7 (A*) { return 29; } +int foo7 (B*) { return 210; } +int test7 () { + C *cp; + return foo7(cp); // 210 +} + +// - Same as above but for references. +int foo8 (A&) { return 211; } +int foo8 (B&) { return 212; } +int test8 () { + C c; + return foo8(c); // 212 +} + +// - Same as above but passing by copy. +int foo9 (A) { return 213; } +int foo9 (B) { return 214; } +int test9 () { + C c; + return foo9(c); // 212 +} + +// - S1 is a conversion of A::* to B::* and S2 is a conversion of +// A::* to C::8. +int foo10 (void (C::*)()) { return 215; } +int foo10 (void (B::*)()) { return 216; } +int test10 () { + void (A::*amp)(); + return foo10(amp); // 216 +} + +//// - S1 is a subsequence of S2 +// FIXME: example needed. +//int foo5 (const int*) { return 23; } +//int foo5 ( int*) { return 24; } +//int test5 () { +// const char a = 5; +// return foo5(&a); // 24 + +/* 3. User defined conversion U1 is better than user defined Conversion U2, + if U1 and U2 are using the same conversion function but U1 has a better + second standard conversion sequence than U2. */ +class D {public: operator short(){ return 0;}}; +int foo11 (float) { return 31; } +int foo11 (int) { return 32; } +int test11 () { + D d; + return foo11(d); // 32 +} + +/* 4. Function Level Ranking. + All else being equal some functions are preferred by overload resolution. + Function F1 is better than function F2 if: */ +// - F1 is a non-template function and F2 is a template function +template int foo12(T) { return 41; } + int foo12(int) { return 42; } +int test12 (){ + return foo12(1); //42 +} + +// - F1 is a more specialized template instance +template int foo13(T) { return 43; } +template int foo13(T*) { return 44; } +int test13 (){ + char *c; + return foo13(c); // 44 +} + +// - The context is user defined conversion and F1 has +// a better return type than F2 +class E { + public: + operator double () {return 45; } + operator int () {return 46; } +}; +int foo14 (int a) {return a;} +int test14 (){ + E e; + return foo14(e); // 46 +} + +int main() { + B b; + foo0(b); + foo1(b); + test1(); + + foo2(b); + test2(); + + foo3(1.0f); + test3(); + + volatile int a; + foo4(&a); + test4(); + + char *c; + foo5(c); + test5(); + + B *bp; + foo6(bp); + test6(); + + C *cp; + foo7(cp); + test7(); + + C co; + foo8(co); + test8(); + + foo9(co); + test9(); + + void (A::*amp)(); + foo10(amp); + test10(); + + D d; + foo11(d); + test11(); + + foo12(1); + test12(); + + foo13(c); + test13(); + + E e; + foo14(e); + test14(); + + return 0; // end of main +} diff --git a/gdb/testsuite/gdb.cp/oranking.exp b/gdb/testsuite/gdb.cp/oranking.exp new file mode 100644 index 0000000..f5cfbb7 --- /dev/null +++ b/gdb/testsuite/gdb.cp/oranking.exp @@ -0,0 +1,96 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set testfile oranking +set srcfile ${testfile}.cc +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug c++}] } { + return -1 +} + +############################################ + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +gdb_breakpoint [gdb_get_line_number "end of main"] +gdb_continue_to_breakpoint "end of main" + +# The 'test*' functions are to prove our understanding +# of the overload resolution performed by the compiler +# So, they should always pass, and the returned value +# should match the corresponding call to 'foo*' + +setup_kfail "gdb/12096" *-*-* +gdb_test "p foo0(b)" "10" + +gdb_test "p test1()" "12" +gdb_test "p foo1(b)" "12" + +gdb_test "p test2()" "13" +setup_kfail "gdb/12098" *-*-* +gdb_test "p foo2(b)" "13" + +gdb_test "p test3()" "21" +gdb_test "p foo3(1.0f)" "21" + +gdb_test "p test4()" "24" +setup_kfail "gdb/12098" *-*-* +gdb_test "p foo4(&a)" "24" + +gdb_test "p test5()" "26" +setup_kfail "gdb/12098" *-*-* +gdb_test "p foo5(c)" "26" + +gdb_test "p test6()" "28" +setup_kfail "gdb/10343" *-*-* +gdb_test "p foo6(bp)" "28" + +gdb_test "p test7()" "210" +setup_kfail "gdb/10343" *-*-* +gdb_test "p foo7(cp)" "210" + +gdb_test "p test8()" "212" +setup_kfail "gdb/10343" *-*-* +gdb_test "p foo8(co)" "212" + +gdb_test "p test9()" "214" +setup_kfail "gdb/12098" *-*-* +gdb_test "p foo9(co)" "214" + +gdb_test "p test10()" "216" +setup_kfail "gdb/12098" *-*-* +gdb_test "p foo10(amp)" "216" + +gdb_test "p test11()" "32" +setup_kfail "gdb/12096" *-*-* +gdb_test "p foo11(d)" "32" + +gdb_test "p test12()" "42" +# this passes only because gdb does not yet +# implement template function calling +gdb_test "p foo12(1)" "42" + +gdb_test "p test13()" "44" +setup_kfail "gdb/12098" *-*-* +gdb_test "p foo13(c)" "44" + +gdb_test "p test14()" "46" +setup_kfail "gdb/12096" *-*-* +gdb_test "p foo14(e)" "46" + + + --------------050405080102060704040304--