[GOLD] fix a current mainline g++ complaint

Message ID 20210520034619.GE1258451@bubble.grove.modra.org
State New
Headers show
Series
  • [GOLD] fix a current mainline g++ complaint
Related show

Commit Message

Alan Modra via Binutils May 20, 2021, 3:46 a.m.
...gold/gc.h:250:37: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [-Werror]
  250 |                 (*secvec).push_back(Section_id(NULL, 0));
      |                                     ^~~~~~~~~~~~~~~~~~~

...stl_pair.h:426:17: note: candidate 1: ‘constexpr std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _U1 = gold::Relobj*; _U2 = unsigned int; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_ConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = true; _T1 = gold::Relobj*; _T2 = unsigned int]’
  426 |       constexpr pair(const _T1& __a, const _T2& __b)
      |                 ^~~~
...stl_pair.h:511:18: note: candidate 2: ‘constexpr std::pair<_T1, _T2>::pair(std::pair<_T1, _T2>::__null_ptr_constant, _U2&&) [with _U2 = int; typename std::enable_if<((! std::__or_<std::is_same<_U2, const _T2&>, std::is_same<_U2, _T2&> >::value) && std::_PCC<true, _T1, _T2>::_DeprConsPair<true, std::nullptr_t, _U2>()), bool>::type <anonymous> = true; _T1 = gold::Relobj*; _T2 = unsigned int]’
  511 |        constexpr pair(__null_ptr_constant, _U2&& __y)
      |                  ^~~~

I don't know enough to say gcc is correct here in the warning, or
whether this should be fixed in stl_pair.h.  So treat this as a heads
up.

	* gc.h (gc_process_relocs): Cast NULL to Relobj* in Section_id
	constructor.


-- 
Alan Modra
Australia Development Lab, IBM

Comments

Alan Modra via Binutils May 20, 2021, 11:26 p.m. | #1
> I don't know enough to say gcc is correct here in the warning, or

> whether this should be fixed in stl_pair.h.  So treat this as a heads

> up.

>

>         * gc.h (gc_process_relocs): Cast NULL to Relobj* in Section_id

>         constructor.


Please add PR gold/27815 to the ChangeLog entry. I was planning on
fixing this by using nullptr instead of NULL, which would have limited
our build environment to GCC 4.6 and later. I just haven't had a
chance to build a GCC 12 for testing yet.

-cary
Alan Modra via Binutils May 21, 2021, 2:19 a.m. | #2
On Thu, May 20, 2021 at 04:26:19PM -0700, Cary Coutant wrote:
> > I don't know enough to say gcc is correct here in the warning, or

> > whether this should be fixed in stl_pair.h.  So treat this as a heads

> > up.

> >

> >         * gc.h (gc_process_relocs): Cast NULL to Relobj* in Section_id

> >         constructor.

> 

> Please add PR gold/27815 to the ChangeLog entry. I was planning on

> fixing this by using nullptr instead of NULL, which would have limited

> our build environment to GCC 4.6 and later. I just haven't had a

> chance to build a GCC 12 for testing yet.


Using nullptr succeeds with gcc-12.  I'm happy to make that change if
you'd prefer it that way.

-- 
Alan Modra
Australia Development Lab, IBM
Alan Modra via Binutils May 21, 2021, 9:57 p.m. | #3
> > >         * gc.h (gc_process_relocs): Cast NULL to Relobj* in Section_id

> > >         constructor.

> >

> > Please add PR gold/27815 to the ChangeLog entry. I was planning on

> > fixing this by using nullptr instead of NULL, which would have limited

> > our build environment to GCC 4.6 and later. I just haven't had a

> > chance to build a GCC 12 for testing yet.

>

> Using nullptr succeeds with gcc-12.  I'm happy to make that change if

> you'd prefer it that way.


Sure. Thanks for checking.

-cary
Alan Modra via Binutils May 25, 2021, 7:01 p.m. | #4
> > > >         * gc.h (gc_process_relocs): Cast NULL to Relobj* in Section_id

> > > >         constructor.

> > >

> > > Please add PR gold/27815 to the ChangeLog entry. I was planning on

> > > fixing this by using nullptr instead of NULL, which would have limited

> > > our build environment to GCC 4.6 and later. I just haven't had a

> > > chance to build a GCC 12 for testing yet.

> >

> > Using nullptr succeeds with gcc-12.  I'm happy to make that change if

> > you'd prefer it that way.

>

> Sure. Thanks for checking.


After learning that it only works with the --std=g++0x option for GCC
4.6, I agree with your assessment that it's not worth it. Thanks!

-cary

Patch

diff --git a/gold/gc.h b/gold/gc.h
index 2c20b44b6ed..6ebd81f3fd0 100644
--- a/gold/gc.h
+++ b/gold/gc.h
@@ -247,7 +247,7 @@  gc_process_relocs(
 	      if (is_ordinary) 
 		(*secvec).push_back(Section_id(src_obj, dst_indx));
 	      else
-                (*secvec).push_back(Section_id(NULL, 0));
+		(*secvec).push_back(Section_id(reinterpret_cast<Relobj*>(NULL), 0));
               // If the target of the relocation is an STT_SECTION symbol,
               // make a note of that by storing -1 in the symbol vector.
               if (lsym.get_st_type() == elfcpp::STT_SECTION)
@@ -329,7 +329,7 @@  gc_process_relocs(
               if (is_ordinary && dst_obj != NULL)
 		(*secvec).push_back(Section_id(dst_obj, dst_indx));
 	      else
-                (*secvec).push_back(Section_id(NULL, 0));
+		(*secvec).push_back(Section_id(reinterpret_cast<Relobj*>(NULL), 0));
               (*symvec).push_back(gsym);
 	      (*addendvec).push_back(std::make_pair(
 					static_cast<long long>(symvalue),