public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101174] New: [12 Regression] CTAD causes instantiation of invalid specialization
@ 2021-06-23  3:41 ppalka at gcc dot gnu.org
  2021-06-23  4:21 ` [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid specialization since r12-926 ppalka at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-23  3:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101174
           Summary: [12 Regression] CTAD causes instantiation of invalid
                    specialization
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

The following testcase

struct S { using type = int; };

template<class T = int, class U = S>
struct multiset {
  using type = typename U::type;
  multiset(T);
  multiset(U);
};

template<class T>
multiset(T) -> multiset<T>;

multiset c(42);

is rejected by GCC 12 with

<stdin>: In instantiation of ‘struct multiset<int, int>’:
<stdin>:13:14:   required from here
<stdin>:5:9: error: ‘int’ is not a class, struct, or union type
<stdin>:7:3: error: ‘multiset<T, U>::multiset(U) [with T = int; U = int]’
cannot be overloaded with ‘multiset<T, U>::multiset(T) [with T = int; U = int]’
<stdin>:6:3: note: previous declaration ‘multiset<T, U>::multiset(T) [with T =
int; U = int]’

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid specialization since r12-926
  2021-06-23  3:41 [Bug c++/101174] New: [12 Regression] CTAD causes instantiation of invalid specialization ppalka at gcc dot gnu.org
@ 2021-06-23  4:21 ` ppalka at gcc dot gnu.org
  2021-06-23 15:03 ` [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid class " ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-23  4:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
            Summary|[12 Regression] CTAD causes |[12 Regression] CTAD causes
                   |instantiation of invalid    |instantiation of invalid
                   |specialization              |specialization since
                   |                            |r12-926
           Keywords|                            |rejects-valid
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r12-926, before which we accepted the testcase.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid class specialization since r12-926
  2021-06-23  3:41 [Bug c++/101174] New: [12 Regression] CTAD causes instantiation of invalid specialization ppalka at gcc dot gnu.org
  2021-06-23  4:21 ` [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid specialization since r12-926 ppalka at gcc dot gnu.org
@ 2021-06-23 15:03 ` ppalka at gcc dot gnu.org
  2021-06-23 21:27 ` cvs-commit at gcc dot gnu.org
  2021-06-23 21:28 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-23 15:03 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid class specialization since r12-926
  2021-06-23  3:41 [Bug c++/101174] New: [12 Regression] CTAD causes instantiation of invalid specialization ppalka at gcc dot gnu.org
  2021-06-23  4:21 ` [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid specialization since r12-926 ppalka at gcc dot gnu.org
  2021-06-23 15:03 ` [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid class " ppalka at gcc dot gnu.org
@ 2021-06-23 21:27 ` cvs-commit at gcc dot gnu.org
  2021-06-23 21:28 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-23 21:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:7da4eae3dcef6fd5d955eb2c80c453aa52368004

commit r12-1762-g7da4eae3dcef6fd5d955eb2c80c453aa52368004
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jun 23 17:23:39 2021 -0400

    c++: excessive instantiation during CTAD [PR101174]

    We set DECL_CONTEXT on implicitly generated deduction guides so that
    their access is consistent with that of the constructor.  But this
    apparently leads to excessive instantiation in some cases, ultimately
    because instantiation of a deduction guide should be independent of
    instantiation of the resulting class specialization, but setting the
    DECL_CONTEXT of the former to the latter breaks this independence.

    To fix this, this patch makes push_access_scope handle artificial
    deduction guides specifically rather than setting their DECL_CONTEXT
    in build_deduction_guide.  We could alternatively make the class
    befriend the guide via DECL_BEFRIENDING_CLASSES, but that wouldn't
    be a complete fix and would break class-deduction-access3.C below
    since friendship isn't transitive.

            PR c++/101174

    gcc/cp/ChangeLog:

            * pt.c (push_access_scope): For artificial deduction guides,
            set the access scope to that of the constructor.
            (pop_access_scope): Likewise.
            (build_deduction_guide): Don't set DECL_CONTEXT on the guide.

    libstdc++-v3/ChangeLog:

            * testsuite/23_containers/multiset/cons/deduction.cc:
            Uncomment CTAD example that was rejected by this bug.
            * testsuite/23_containers/set/cons/deduction.cc: Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1z/class-deduction-access3.C: New test.
            * g++.dg/cpp1z/class-deduction91.C: New test.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid class specialization since r12-926
  2021-06-23  3:41 [Bug c++/101174] New: [12 Regression] CTAD causes instantiation of invalid specialization ppalka at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-06-23 21:27 ` cvs-commit at gcc dot gnu.org
@ 2021-06-23 21:28 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-23 21:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-23 21:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23  3:41 [Bug c++/101174] New: [12 Regression] CTAD causes instantiation of invalid specialization ppalka at gcc dot gnu.org
2021-06-23  4:21 ` [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid specialization since r12-926 ppalka at gcc dot gnu.org
2021-06-23 15:03 ` [Bug c++/101174] [12 Regression] CTAD causes instantiation of invalid class " ppalka at gcc dot gnu.org
2021-06-23 21:27 ` cvs-commit at gcc dot gnu.org
2021-06-23 21:28 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).