Bug 15372 - ref qualifiers and overloading
Summary: ref qualifiers and overloading
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: archer
Depends on:
Blocks: 16106
  Show dependency treegraph
 
Reported: 2013-04-15 20:07 UTC by Tom Tromey
Modified: 2026-03-31 18:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Tromey 2013-04-15 20:07:21 UTC
C++11 added "&" and "&&" ref qualifiers.
These are used in overload resolution.
There isn't any DWARF support for them yet, see
  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56974
But once this information is available, gdb should use it.
Comment 1 Keith Seitz 2017-03-09 22:30:23 UTC
Many years later, we have DWARF support for rvalue references and we even have pending support for them in GDB (see c++/14441). However, that patch series still has some problems with overload resolution.

I'm using this bug to track these problems. In our test suite, we (will) have:

FAIL: gdb.cp/rvalue-ref-overload.exp: lvalue reference overload
FAIL: gdb.cp/rvalue-ref-overload.exp: rvalue reference overload
FAIL: gdb.cp/rvalue-ref-params.exp: print value of f1 on Child&& in f2

These will be marked KFAIL and linked to this bug.
Comment 2 Sourceware Commits 2026-03-17 18:10:46 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=883363daadfa6fc4f9221546f448bfa6a87dd447

commit 883363daadfa6fc4f9221546f448bfa6a87dd447
Author: Keith Seitz <keiths@redhat.com>
Date:   Thu Oct 16 08:29:05 2025 -0700

    infcall: Add support for integer literals as reference function parameters
    
    This patch attempts to mitigate the shortcomings of passing literals
    to inferior function calls requiring references.  The specific use case here
    is std::map's operator[]:
    
    std::map int_map<int, int>;
    int_map[1] = 10;
    (gdb) print int_map[1]
    Attempt to take address of value not located in memory.
    
    This is occurring because while value_coerce_to_target understands
    that some values need to be allocated and copied to the inferior's
    memory, it only considers the actual parsed type of the argument value,
    ignoring the actual type of the function parameter. That is,
    in this specific case, the value's parsed type is TYPE_CODE_INT, but
    the function requires TYPE_CODE_REF. We need to account for the
    reference.
    
    In value_arg_coerce, we have special handling for references, but it
    has not specifically dealt with this case. It now checks if the
    reference is in memory, and if it isn't, it copies it, if the type
    is trivially copyable.
    
    As a result of this patch, the last remaining failure in c++/15372 is now
    fixed, and that bug can be closed.
    
    With this patch, we can now print map entries with integer keys:
    
    (gdb) print int_map[1]
    $1 = (std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > >::mapped_type &) @0x41f2d4: 10
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=15372
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25957
    Approved-By: Andrew Burgess <aburgess@redhat.com>
Comment 3 Keith Seitz 2026-03-31 18:16:57 UTC
The last issues should now be resolved, and the KFAILs
have been removed.