<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="4.4+"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>13225</bug_id>
          
          <creation_ts>2011-09-26 15:36:00 +0000</creation_ts>
          <short_desc>GDB fails to find non-overloaded C++ function</short_desc>
          <delta_ts>2011-10-28 15:33:08 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>gdb</product>
          <component>c++</component>
          <version>unknown</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>7.4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jim Blandy">jimb</reporter>
          <assigned_to name="Keith Seitz">keiths</assigned_to>
          <cc>keiths</cc>
    
    <cc>rguenth</cc>
          <cf_gcchost></cf_gcchost>
          <cf_gcctarget></cf_gcctarget>
          <cf_gccbuild></cf_gccbuild>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>50765</commentid>
    <comment_count>0</comment_count>
    <who name="Jim Blandy">jimb</who>
    <bug_when>2011-09-26 15:36:37 +0000</bug_when>
    <thetext>When I try to call JS_CompileFunction in the following test program, GDB says:

Cannot resolve function JS_CompileFunction to any overloaded instance

However, if I cast one of the zeros to &quot;const char **&quot;, GDB can find the function.

$ cat archer-bug.cpp
#include &lt;stdlib.h&gt;

typedef unsigned uintN;

struct JSContext;
struct JSFunction;
struct JSObject;

JSFunction *
JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
                   uintN nargs, const char **argnames,
                   const char *bytes, size_t length,
                   const char *filename, uintN lineno) { }


int main(int argc, char **argv) {
  JSContext *cx = NULL;
  JSObject *global = NULL;
  JS_CompileFunction(cx, global, &quot;f&quot;, 0, 0, &quot;1&quot;, 1, &quot;foo.js&quot;, 1);
  return 0;
}
$ g++ -g archer-bug.cpp -o archer-bug$ ~/gdb/bin/gdb archer-bug
GNU gdb (GDB) 7.3.50.20110925-cvs
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type &quot;show copying&quot;
and &quot;show warranty&quot; for details.
This GDB was configured as &quot;x86_64-unknown-linux-gnu&quot;.
For bug reporting instructions, please see:
&lt;http://www.gnu.org/software/gdb/bugs/&gt;...
Reading symbols from /home/jimb/play/archer-bug...done.
(gdb) start
Temporary breakpoint 1 at 0x4005a1: file archer-bug.cpp, line 17.
Starting program: /home/jimb/play/archer-bug 

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffe738) at archer-bug.cpp:17
17	  JSContext *cx = NULL;
(gdb) next
18	  JSObject *global = NULL;
(gdb) 
19	  JS_CompileFunction(cx, global, &quot;f&quot;, 0, 0, &quot;1&quot;, 1, &quot;foo.js&quot;, 1);
(gdb) 
20	  return 0;
(gdb) p JS_CompileFunction(cx, global, &quot;f&quot;, 0, 0, &quot;1&quot;, 1, &quot;foo.js&quot;, 1)
Cannot resolve function JS_CompileFunction to any overloaded instance
(gdb) p JS_CompileFunction(cx, global, &quot;f&quot;, 0, (const char **) 0, &quot;1&quot;, 1, &quot;foo.js&quot;, 1)
$1 = NULL
(gdb)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51029</commentid>
    <comment_count>1</comment_count>
    <who name="Keith Seitz">keiths</who>
    <bug_when>2011-10-11 18:53:23 +0000</bug_when>
    <thetext>There are actually two problems mentioned here. First, the fact that the parser is seeing the NULL (&quot;0&quot;) char const** parameter as an INT, but the evaluator will not allow that conversion. I don&apos;t see why we couldn&apos;t permit that. I can imagine scenarios where the user might want to pass an address this way. While a real source file would require the cast, there is no reason why we cannot be a little more permissive in the debugger.

Second, there is a bug alluded to by the OP: casting the first &quot;0&quot; to some other type will get gdb to &quot;work.&quot; This is happening because when the function&apos;s overload suitability is calculated, the code is currently early returning on the very first non-STANDARD rank that it sees, instead of returning the worst one that it sees.

Patch/tests pending.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51030</commentid>
    <comment_count>2</comment_count>
    <who name="Keith Seitz">keiths</who>
    <bug_when>2011-10-11 19:24:27 +0000</bug_when>
    <thetext>Patch submitted:
http://sourceware.org/ml/gdb-patches/2011-10/msg00327.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51031</commentid>
    <comment_count>3</comment_count>
    <who name="Jim Blandy">jimb</who>
    <bug_when>2011-10-11 19:30:21 +0000</bug_when>
    <thetext>Thanks for the patch, Keith!

You say:

While a real source file would require the cast, there is no reason why we cannot be a little more permissive in the debugger.

I don&apos;t think that&apos;s correct. The transcript (with its missing newline after the g++ command...) shows that the expression I try to evaluate in GDB is identical to the expression appearing in the source code, which the compiler accepts without complaint. The C++ language does not require that cast.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51113</commentid>
    <comment_count>4</comment_count>
    <who name="cvs-commit@gcc.gnu.org">cvs-commit</who>
    <bug_when>2011-10-14 20:22:26 +0000</bug_when>
    <thetext>CVSROOT:	/cvs/src
Module name:	src
Changes by:	kseitz@sourceware.org	2011-10-14 20:22:17

Modified files:
	gdb            : ChangeLog eval.c gdbtypes.h gdbtypes.c 
	                 valarith.c valops.c value.h 

Log message:
	PR c++/13225
	* eval.c (evaluate_subexp_standard): Do not construct
	an array of types; pass the value array directly to
	find_overload_match.
	* gdbtypes.h (NULL_POINTER_CONVERSION_BADNESS): Declare.
	(rank_function): Take an array of values instead of types.
	(rank_one_type): Add struct value * parameter.
	* gdbtypes.c (NULL_POINTER_CONVERSION_BADNESS): Define.
	(rank_function): For each argument, pass the argument&apos;s
	value to rank_one_type.
	(rank_one_type): Add VALUE parameter.
	If the parameter type is a pointer and the argument type
	is an integer, return NULL_POINTER_CONVERSION_BADNESS if
	VALUE is zero.
	Update all calls to rank_one_type, passing NULL for new
	VALUE parameter.
	* valarith.c (value_user_defined_cpp_op): Do not construct
	an array of types; pass the value array directly to
	find_overload_match.
	* valops.c (find_overload_method_list): Take an array of
	values instead of types.
	Save the type of OBJP for later use.
	Update calls to find_oload_champ, and find_oload_champ_namespace.
	(find_oload_champ_namespace): Take an array of values instead
	of types.
	(find_oload_champ_namespace_loop): Likewise.
	(find_oload_champ): Likewise.
	(classify_oload_match): Inspect all arguments
	until INCOMPATIBLE is found. Return the worst badness found
	otherwise.
	(compare_parameters): Update call to rank_one_type.
	* value.h (find_overload_match): Take an array of values instead
	of types.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&amp;r1=1.13437&amp;r2=1.13438
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/eval.c.diff?cvsroot=src&amp;r1=1.154&amp;r2=1.155
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbtypes.h.diff?cvsroot=src&amp;r1=1.156&amp;r2=1.157
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbtypes.c.diff?cvsroot=src&amp;r1=1.219&amp;r2=1.220
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/valarith.c.diff?cvsroot=src&amp;r1=1.99&amp;r2=1.100
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/valops.c.diff?cvsroot=src&amp;r1=1.287&amp;r2=1.288
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/value.h.diff?cvsroot=src&amp;r1=1.187&amp;r2=1.188</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51114</commentid>
    <comment_count>5</comment_count>
    <who name="cvs-commit@gcc.gnu.org">cvs-commit</who>
    <bug_when>2011-10-14 20:23:01 +0000</bug_when>
    <thetext>CVSROOT:	/cvs/src
Module name:	src
Changes by:	kseitz@sourceware.org	2011-10-14 20:22:50

Modified files:
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.cp: converts.exp converts.cc 

Log message:
	PR c++/13225
	* gdb.cp/converts.cc (foo3_1): New function.
	(foo3_2): New functions.
	* gdb.cp/converts.exp: Add tests for int to pointer conversion
	and null pointer conversions of integer constant zero.
	Add test to check if all arguments are checked for incompatible
	conversion BADNESS.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&amp;r1=1.2897&amp;r2=1.2898
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/converts.exp.diff?cvsroot=src&amp;r1=1.3&amp;r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/converts.cc.diff?cvsroot=src&amp;r1=1.2&amp;r2=1.3</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51115</commentid>
    <comment_count>6</comment_count>
    <who name="Keith Seitz">keiths</who>
    <bug_when>2011-10-14 20:30:39 +0000</bug_when>
    <thetext>Final patch committed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51423</commentid>
    <comment_count>7</comment_count>
    <who name="Pedro Alves">palves</who>
    <bug_when>2011-10-28 15:33:08 +0000</bug_when>
    <thetext>*** Bug 13356 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>