Bug 26344

Summary: [build, gcc 4.8] error: no matching function for call to 'std::pair<const riscv_gdbarch_features, const std::unique_ptr<target_desc, target_desc_deleter> >::pair(const riscv_gdbarch_features&, target_desc*&)'
Product: gdb Reporter: Tom de Vries <vries>
Component: buildAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: andrew.burgess, palmer, simark
Priority: P2    
Version: HEAD   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Tom de Vries 2020-08-07 08:02:54 UTC
src/gdb/arch/riscv.c:112:45:   required from here
/usr/include/c++/4.8/bits/hashtable_policy.h:195:39: error: no matching function for call to 'std::pair<const riscv_gdbarch_features, const std::unique_ptr<target_desc, target_desc_deleter> >::pair(const riscv_gdbarch_features&, target_desc*&)'
  : _M_v(std::forward<_Args>(__args)...) { }
                                       ^
Comment 1 Tom de Vries 2020-08-07 09:25:14 UTC
Tentative fix:
...
diff --git a/gdb/arch/riscv.c b/gdb/arch/riscv.c
index e43aafc1c2..dbedb99c94 100644
--- a/gdb/arch/riscv.c
+++ b/gdb/arch/riscv.c
@@ -109,7 +109,7 @@ riscv_lookup_target_description (const struct riscv_gdbarch_featur
es features)
   target_desc *tdesc = riscv_create_target_description (features);
 
   /* Add to the cache.  */
-  riscv_tdesc_cache.emplace (features, tdesc);
+  riscv_tdesc_cache.emplace (features, target_desc_up (tdesc));
 
   return tdesc;
 }
...

Looks somewhat similar to commit 6d0cf4464e "Fix build with gcc-4.8.x".
Comment 2 Andrew Burgess 2020-08-07 10:01:34 UTC
I have this patch here:
  https://sourceware.org/pipermail/gdb-patches/2020-July/170639.html

that I'd completely forgotten about.  I don't know if this applies cleanly to head still, but it looks like it should fix the issue... maybe.

I can rebase and test this if you'd be happy for this to go in instead?
Comment 3 Andrew Burgess 2020-08-07 10:02:37 UTC
I should have said, your patch looks fine if we only wanted to fix RISC-V.
Comment 4 Tom de Vries 2020-08-07 11:35:28 UTC
(In reply to Andrew Burgess from comment #3)
> I should have said, your patch looks fine if we only wanted to fix RISC-V.

AFAICT the problem reported in this issue only happens in riscv.c (I should probably try this gdb_mbuild.sh that I heard about recently to know for sure).

(In reply to Andrew Burgess from comment #2)
> I have this patch here:
>   https://sourceware.org/pipermail/gdb-patches/2020-July/170639.html
> 
> that I'd completely forgotten about.  I don't know if this applies cleanly
> to head still,

It does.

> but it looks like it should fix the issue... maybe.
> 

I checked, and it does fix the build.

> I can rebase and test this if you'd be happy for this to go in instead?

I'd rather commit this minimal workaround first.

That said, I've looked at your patch, and it looks ok to me.  I'm not sure if timingwise is makes sense to wait after gdb-10 branching to commit this, just a thought.
Comment 5 Tom de Vries 2020-08-08 17:14:40 UTC
Hmm, commit 888bdb2b74 "gdb: change regcache list to be a map" just introduced another occurrence.
Comment 6 cvs-commit@gcc.gnu.org 2020-08-08 21:34:23 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

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

commit 38f8aa06d9c422934e635779783107c0d3be419a
Author: Tom de Vries <tdevries@suse.de>
Date:   Sat Aug 8 23:34:19 2020 +0200

    [gdb/build] Fix missing implicit constructor call with gcc 4.8
    
    When building gdb on x86_64-linux with --enable-targets riscv64-suse-linux, I
    run into:
    ...
    src/gdb/arch/riscv.c:112:45:   required from here
    /usr/include/c++/4.8/bits/hashtable_policy.h:195:39: error: no matching \
      function for call to 'std::pair<const riscv_gdbarch_features, const \
      std::unique_ptr<target_desc, target_desc_deleter> >::pair(const \
      riscv_gdbarch_features&, target_desc*&)'
      : _M_v(std::forward<_Args>(__args)...) { }
                                           ^
    ...
    for this code in riscv_lookup_target_description:
    ...
      /* Add to the cache.  */
      riscv_tdesc_cache.emplace (features, tdesc);
    ...
    
    Work around this compiler problem (filed as PR gcc/96537), similar to how that
    was done in commit 6d0cf4464e "Fix build with gcc-4.8.x":
    ...
    -  riscv_tdesc_cache.emplace (features, tdesc);
    +  riscv_tdesc_cache.emplace (features, target_desc_up (tdesc));
    ...
    That is, call the target_desc_up constructor explictly instead of implicitly.
    
    Also, work around a similar issue in get_thread_arch_aspace_regcache.
    
    Build on x86_64-linux with --enable-targets riscv64-suse-linux, and
    reg-tested.
    
    gdb/ChangeLog:
    
    2020-08-08  Tom de Vries  <tdevries@suse.de>
    
            PR build/26344
            * arch/riscv.c (riscv_lookup_target_description): Use an explicit
            constructor.
            * regcache.c (get_thread_arch_aspace_regcache): Same.
Comment 7 Tom de Vries 2020-08-08 21:36:00 UTC
Patch fixing build with gcc 4.8 committed, marking resolved-fixed.
Comment 8 Tom de Vries 2020-08-10 11:55:12 UTC
(In reply to cvs-commit@gcc.gnu.org from comment #6)
>     Work around this compiler problem (filed as PR gcc/96537),

FTR, the gcc PR was marked as invalid.

The fact that the code compiles with g++-7.5.0 -std=c++11, and doesn't with g++-4.8.5 -std=c++11 doesn't indicate a bug in g++-4.8.5, but that a language update ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4387 ) was retroactively applied to older standard modes in g++-7.5.0.
Comment 9 Simon Marchi 2020-08-10 12:55:49 UTC
Ok, thanks for investigating and fixing it.  At least, it's easy to please all compilers.