public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114974] New: CTAD: gcc rejects some valid code
@ 2024-05-07 14:07 hokein.wu at gmail dot com
  2024-05-07 22:54 ` [Bug c++/114974] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hokein.wu at gmail dot com @ 2024-05-07 14:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114974
           Summary: CTAD: gcc rejects some valid code
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hokein.wu at gmail dot com
  Target Milestone: ---

gcc trunk rejects the following valid CTAD code:

```
template<typename T1>
struct A1 {
  template<typename T2>
  struct A2 { T2 t; };
};

template <typename K>
void s(K k) {
  A1<int>::A2 a(2);
}

void s() {
  s<double>(1.0);
}
```

https://godbolt.org/z/7bxEbhP47

It looks like in this case gcc fails? to generate the aggregate deduction
guide.

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

* [Bug c++/114974] CTAD: gcc rejects some valid code
  2024-05-07 14:07 [Bug c++/114974] New: CTAD: gcc rejects some valid code hokein.wu at gmail dot com
@ 2024-05-07 22:54 ` pinskia at gcc dot gnu.org
  2024-05-13 13:53 ` [Bug c++/114974] CTAD; templated inner class of template class seems to be handled incorrectly cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-07 22:54 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-05-07
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Slightly reduced:
```
template<typename T1>
struct A1 {
  template<typename T2>
  struct A2 { T2 t; };
};
void s(double k) {
  A1<int>::A2 a(2);
}
```

It looks like the deduction guide is not being generated correctly when the
inner template class is of a templated class. If A1 was not a template, GCC
acecpts the code just fine. that is:
```
struct A1 {
  template<typename T2>
  struct A2 { T2 t; };
};
void s(double k) {
  A1::A2 a(2);
}
```
Works just fine.

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

* [Bug c++/114974] CTAD; templated inner class of template class seems to be handled incorrectly
  2024-05-07 14:07 [Bug c++/114974] New: CTAD: gcc rejects some valid code hokein.wu at gmail dot com
  2024-05-07 22:54 ` [Bug c++/114974] " pinskia at gcc dot gnu.org
@ 2024-05-13 13:53 ` cvs-commit at gcc dot gnu.org
  2024-05-13 15:39 ` cvs-commit at gcc dot gnu.org
  2024-05-13 15:40 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-13 13:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC 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:6d31a370e26eeb950c326332633b3e8e84b6630b

commit r15-434-g6d31a370e26eeb950c326332633b3e8e84b6630b
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon May 13 09:53:40 2024 -0400

    c++: nested aggregate/alias CTAD fixes [PR114974, PR114901, PR114903]

    During maybe_aggr_guide with a nested class template and paren init,
    like with list init we need to consider the generic template type rather
    than the partially instantiated type since partial instantiations don't
    have (partially instantiated) TYPE_FIELDS.  In turn we need to partially
    substitute PARMs in the paren init case as well.  As a drive-by improvement
    it seems better to use outer_template_args instead of DECL_TI_ARGS during
    this partial substitution so that we lower instead of substitute the
    innermost template parameters, which is generally more robust.

    And during alias_ctad_tweaks with a nested class template, even though
    the guides may be already partially instantiated we still need to
    substitute the outermost arguments into its constraints.

            PR c++/114974
            PR c++/114901
            PR c++/114903

    gcc/cp/ChangeLog:

            * pt.cc (maybe_aggr_guide): Fix obtaining TYPE_FIELDS in
            the paren init case.  Hoist out partial substitution logic
            to apply to the paren init case as well.
            (alias_ctad_tweaks): Substitute outer template arguments into
            a guide's constraints.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/class-deduction-aggr14.C: New test.
            * g++.dg/cpp2a/class-deduction-alias20.C: New test.
            * g++.dg/cpp2a/class-deduction-alias21.C: New test.

    Reviewed-by: Jason Merrill <jason@redhat.com>

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

* [Bug c++/114974] CTAD; templated inner class of template class seems to be handled incorrectly
  2024-05-07 14:07 [Bug c++/114974] New: CTAD: gcc rejects some valid code hokein.wu at gmail dot com
  2024-05-07 22:54 ` [Bug c++/114974] " pinskia at gcc dot gnu.org
  2024-05-13 13:53 ` [Bug c++/114974] CTAD; templated inner class of template class seems to be handled incorrectly cvs-commit at gcc dot gnu.org
@ 2024-05-13 15:39 ` cvs-commit at gcc dot gnu.org
  2024-05-13 15:40 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-13 15:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:57cd8665fea4c339369a43be017583621aa82fed

commit r14-10201-g57cd8665fea4c339369a43be017583621aa82fed
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon May 13 09:53:40 2024 -0400

    c++: nested aggregate/alias CTAD fixes [PR114974, PR114901, PR114903]

    During maybe_aggr_guide with a nested class template and paren init,
    like with list init we need to consider the generic template type rather
    than the partially instantiated type since partial instantiations don't
    have (partially instantiated) TYPE_FIELDS.  In turn we need to partially
    substitute PARMs in the paren init case as well.  As a drive-by improvement
    it seems better to use outer_template_args instead of DECL_TI_ARGS during
    this partial substitution so that we lower instead of substitute the
    innermost template parameters, which is generally more robust.

    And during alias_ctad_tweaks with a nested class template, even though
    the guides may be already partially instantiated we still need to
    substitute the outermost arguments into its constraints.

            PR c++/114974
            PR c++/114901
            PR c++/114903

    gcc/cp/ChangeLog:

            * pt.cc (maybe_aggr_guide): Fix obtaining TYPE_FIELDS in
            the paren init case.  Hoist out partial substitution logic
            to apply to the paren init case as well.
            (alias_ctad_tweaks): Substitute outer template arguments into
            a guide's constraints.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/class-deduction-aggr14.C: New test.
            * g++.dg/cpp2a/class-deduction-alias20.C: New test.
            * g++.dg/cpp2a/class-deduction-alias21.C: New test.

    Reviewed-by: Jason Merrill <jason@redhat.com>
    (cherry picked from commit 6d31a370e26eeb950c326332633b3e8e84b6630b)

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

* [Bug c++/114974] CTAD; templated inner class of template class seems to be handled incorrectly
  2024-05-07 14:07 [Bug c++/114974] New: CTAD: gcc rejects some valid code hokein.wu at gmail dot com
                   ` (2 preceding siblings ...)
  2024-05-13 15:39 ` cvs-commit at gcc dot gnu.org
@ 2024-05-13 15:40 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-05-13 15:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.2
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14.2, thanks for the reports.

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

end of thread, other threads:[~2024-05-13 15:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-07 14:07 [Bug c++/114974] New: CTAD: gcc rejects some valid code hokein.wu at gmail dot com
2024-05-07 22:54 ` [Bug c++/114974] " pinskia at gcc dot gnu.org
2024-05-13 13:53 ` [Bug c++/114974] CTAD; templated inner class of template class seems to be handled incorrectly cvs-commit at gcc dot gnu.org
2024-05-13 15:39 ` cvs-commit at gcc dot gnu.org
2024-05-13 15:40 ` 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).