https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101174

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-06-23
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot 
gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
The particular problem here is that during dguide overload resolution for
multiset(42), we briefly consider the implicit deduction guide for the second
ctor:

  template<class T = int, class U = S>
  multiset(U) -> multiset<T, U>

which after substituting deduced template arguments becomes

  multiset(int) -> multiset<int, int>

and after r12-926, its (substituted) DECL_CONTEXT is also multiset<int, int>
rather than empty.

Since DECL_CLASS_SCOPE_P is now true for implicit deduction guides, we try to
complete/instantiate its DECL_CONTEXT via the call to DERIVED_FROM_P in
joust():

  /* F1 is a member of a class D, F2 is a member of a base class B of D, and
     for all arguments the corresponding parameters of F1 and F2 have the same
     type (CWG 2273/2277). */
  if (DECL_P (cand1->fn) && DECL_CLASS_SCOPE_P (cand1->fn)
      && !DECL_CONV_FN_P (cand1->fn)
      && DECL_P (cand2->fn) && DECL_CLASS_SCOPE_P (cand2->fn)
      && !DECL_CONV_FN_P (cand2->fn))
    {
      tree base1 = DECL_CONTEXT (strip_inheriting_ctors (cand1->fn));
      tree base2 = DECL_CONTEXT (strip_inheriting_ctors (cand2->fn));

      bool used1 = false;
      bool used2 = false;
      if (base1 == base2)
        /* No difference.  */;
      else if (DERIVED_FROM_P (base1, base2)) // XXX
        used1 = true;
      else if (DERIVED_FROM_P (base2, base1))
        used2 = true;

which results in the hard error seen.

I'm testing setting DECL_BEFRIENDING_CLASSES instead of DECL_CONTEXT on an
implicit deduction guide, to avoid such accidental instantiations

Reply via email to