public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack
@ 2022-11-23 23:39 davidfromonline at gmail dot com
  2022-11-24  1:04 ` [Bug c++/107853] Cannot create friend function template with a requires uses the " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: davidfromonline at gmail dot com @ 2022-11-23 23:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107853
           Summary: Cannot create friend function template with variadic
                    pack that depends on variadic pack
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfromonline at gmail dot com
  Target Milestone: ---

The following valid translation unit

```
template<typename, typename>
concept c = true;

template<typename... Ts>
struct s {
        template<typename... Us> requires (... and c<Us, Ts>)
        friend void f(Us...) {
        }
};

auto x = s<>();
```

is rejected by gcc with the error message


```
<source>: In instantiation of 'struct s<>':
<source>:11:14:   required from here
<source>:6:27: error: mismatched argument pack lengths while expanding 'c<Us,
Ts>'
    6 |         template<c<Ts>... Us>
      |                           ^~
Compiler returned: 1
```

See it live: https://godbolt.org/z/4qGKP9K9a

Note that adding a single template parameter to the instantiated `s`, for
instance, `s<int>`, causes gcc to ICE:

```
template<typename, typename>
concept c = true;

template<typename... Ts>
struct s {
        template<typename... Us> requires (... and c<Us, Ts>)
        friend void f(Us...) {
        }
};

auto x = s<int>();
```

```
<source>: In instantiation of 'struct s<int>':
<source>:11:17:   required from here
<source>:6:52: internal compiler error: in use_pack_expansion_extra_args_p, at
cp/pt.cc:12674
    6 |         template<typename... Us> requires (... and c<Us, Ts>)
      |                                           ~~~~~~~~~^~~~~~~~~~
0x22f921e internal_error(char const*, ...)
        ???:0
0xa4d7bc fancy_abort(char const*, int, char const*)
        ???:0
0xac1bb0 tsubst_constraint(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xac1c99 maybe_substitute_reqs_for(tree_node*, tree_node const*)
        ???:0
0xc7e28c instantiate_class_template(tree_node*)
        ???:0
0xccdb7f complete_type_or_maybe_complain(tree_node*, tree_node*, int)
        ???:0
0xcef1a8 build_functional_cast(unsigned int, tree_node*, tree_node*, int)
        ???:0
0xc26267 c_parse_file()
        ???:0
0xd61389 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```

See it live: https://godbolt.org/z/3dfvb5ov3


Using terse syntax (`template<c<Ts>... Us>`) has the same behavior.

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

* [Bug c++/107853] Cannot create friend function template with a requires uses the variadic pack
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
@ 2022-11-24  1:04 ` pinskia at gcc dot gnu.org
  2022-11-24  1:09 ` [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-24  1:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-11-24
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=85241
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, related to PR 85241.

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

* [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
  2022-11-24  1:04 ` [Bug c++/107853] Cannot create friend function template with a requires uses the " pinskia at gcc dot gnu.org
@ 2022-11-24  1:09 ` pinskia at gcc dot gnu.org
  2022-12-21  9:52 ` rguenth at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-24  1:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |9.5.0
           Keywords|                            |ice-checking,
                   |                            |ice-on-valid-code
      Known to fail|                            |10.1.0
   Target Milestone|---                         |10.5
            Summary|variadic template with a    |[10/11/12/13 Regression]
                   |variadic template friend    |variadic template with a
                   |with a requires of fold     |variadic template friend
                   |expression                  |with a requires of fold
                   |                            |expression

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am not 100% sure we can call this a regression but GCC 9.5.0 accepts the code
for the first example.

The second example looks like it only ICEs with checking enabled ...

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

* [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
  2022-11-24  1:04 ` [Bug c++/107853] Cannot create friend function template with a requires uses the " pinskia at gcc dot gnu.org
  2022-11-24  1:09 ` [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression pinskia at gcc dot gnu.org
@ 2022-12-21  9:52 ` rguenth at gcc dot gnu.org
  2022-12-21 16:09 ` ppalka at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-21  9:52 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
            Version|unknown                     |13.0

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

* [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (2 preceding siblings ...)
  2022-12-21  9:52 ` rguenth at gcc dot gnu.org
@ 2022-12-21 16:09 ` ppalka at gcc dot gnu.org
  2022-12-21 16:09 ` ppalka at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-12-21 16:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |danakj at orodu dot net

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 108066 has been marked as a duplicate of this bug. ***

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

* [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (3 preceding siblings ...)
  2022-12-21 16:09 ` ppalka at gcc dot gnu.org
@ 2022-12-21 16:09 ` ppalka at gcc dot gnu.org
  2022-12-21 16:10 ` ppalka at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-12-21 16:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 108067 has been marked as a duplicate of this bug. ***

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

* [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (4 preceding siblings ...)
  2022-12-21 16:09 ` ppalka at gcc dot gnu.org
@ 2022-12-21 16:10 ` ppalka at gcc dot gnu.org
  2022-12-23 14:18 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-12-21 16:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

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

* [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (5 preceding siblings ...)
  2022-12-21 16:10 ` ppalka at gcc dot gnu.org
@ 2022-12-23 14:18 ` cvs-commit at gcc dot gnu.org
  2022-12-23 14:19 ` [Bug c++/107853] [10/11/12 " ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-23 14:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 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:bd1fc4a219d8c0fad0ec41002e895b49e384c1c2

commit r13-4876-gbd1fc4a219d8c0fad0ec41002e895b49e384c1c2
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Dec 23 09:18:37 2022 -0500

    c++: template friend with variadic constraints [PR107853]

    When instantiating a constrained hidden template friend, we substitute
    into its template-head requirements in tsubst_friend_function.  For this
    substitution we use the template's full argument vector whose outer
    levels correspond to the instantiated class's arguments and innermost
    level corresponds to the template's own level-lowered generic arguments.

    But for A<int>::f here, for which the relevant argument vector is
    {{int}, {Us...}}, the substitution into (C<Ts, Us> && ...) triggers the
    assert in use_pack_expansion_extra_args_p since one argument is a pack
    expansion and the other isn't.

    And for A<int, int>::f, for which the relevant argument vector is
    {{int, int}, {Us...}}, the use_pack_expansion_extra_args_p assert would
    also trigger but we first get a bogus "mismatched argument pack lengths"
    error from tsubst_pack_expansion.

    Sidestepping the question of whether tsubst_pack_expansion should be
    able to handle such substitutions, it seems we can work around this by
    using only the instantiated class's arguments and not also the template
    friend's own generic arguments, which is consistent with how we normally
    substitute into the signature of a member template.

            PR c++/107853

    gcc/cp/ChangeLog:

            * constraint.cc (maybe_substitute_reqs_for): Substitute into
            the template-head requirements of a template friend using only
            its outer arguments via outer_template_args.
            * cp-tree.h (outer_template_args): Declare.
            * pt.cc (outer_template_args): Define, factored out and
            generalized from ...
            (ctor_deduction_guides_for): ... here.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-friend12.C: New test.
            * g++.dg/cpp2a/concepts-friend13.C: New test.

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

* [Bug c++/107853] [10/11/12 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (6 preceding siblings ...)
  2022-12-23 14:18 ` cvs-commit at gcc dot gnu.org
@ 2022-12-23 14:19 ` ppalka at gcc dot gnu.org
  2023-03-07  2:18 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-12-23 14:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11/12/13 Regression]    |[10/11/12 Regression]
                   |variadic template with a    |variadic template with a
                   |variadic template friend    |variadic template friend
                   |with a requires of fold     |with a requires of fold
                   |expression                  |expression
      Known to work|                            |13.0

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed on trunk so far

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

* [Bug c++/107853] [10/11/12 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (7 preceding siblings ...)
  2022-12-23 14:19 ` [Bug c++/107853] [10/11/12 " ppalka at gcc dot gnu.org
@ 2023-03-07  2:18 ` cvs-commit at gcc dot gnu.org
  2023-04-05 20:16 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-07  2:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:cb39089c5a0da1e9b16ad27db557a2c3f930e668

commit r12-9229-gcb39089c5a0da1e9b16ad27db557a2c3f930e668
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Dec 23 09:18:37 2022 -0500

    c++: template friend with variadic constraints [PR107853]

    When instantiating a constrained hidden template friend, we substitute
    into its template-head requirements in tsubst_friend_function.  For this
    substitution we use the template's full argument vector whose outer
    levels correspond to the instantiated class's arguments and innermost
    level corresponds to the template's own level-lowered generic arguments.

    But for A<int>::f here, for which the relevant argument vector is
    {{int}, {Us...}}, the substitution into (C<Ts, Us> && ...) triggers the
    assert in use_pack_expansion_extra_args_p since one argument is a pack
    expansion and the other isn't.

    And for A<int, int>::f, for which the relevant argument vector is
    {{int, int}, {Us...}}, the use_pack_expansion_extra_args_p assert would
    also trigger but we first get a bogus "mismatched argument pack lengths"
    error from tsubst_pack_expansion.

    Sidestepping the question of whether tsubst_pack_expansion should be
    able to handle such substitutions, it seems we can work around this by
    using only the instantiated class's arguments and not also the template
    friend's own generic arguments, which is consistent with how we normally
    substitute into the signature of a member template.

            PR c++/107853

    gcc/cp/ChangeLog:

            * constraint.cc (maybe_substitute_reqs_for): Substitute into
            the template-head requirements of a template friend using only
            its outer arguments via outer_template_args.
            * cp-tree.h (outer_template_args): Declare.
            * pt.cc (outer_template_args): Define, factored out and
            generalized from ...
            (ctor_deduction_guides_for): ... here.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-friend12.C: New test.
            * g++.dg/cpp2a/concepts-friend13.C: New test.

    (cherry picked from commit bd1fc4a219d8c0fad0ec41002e895b49e384c1c2)

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

* [Bug c++/107853] [10/11/12 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (8 preceding siblings ...)
  2023-03-07  2:18 ` cvs-commit at gcc dot gnu.org
@ 2023-04-05 20:16 ` mpolacek at gcc dot gnu.org
  2023-04-06 13:25 ` [Bug c++/107853] [10/11 " ppalka at gcc dot gnu.org
  2023-07-07 10:44 ` [Bug c++/107853] [11 " rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-04-05 20:16 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |h2+bugs at fsfe dot org

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
*** Bug 109425 has been marked as a duplicate of this bug. ***

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

* [Bug c++/107853] [10/11 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (9 preceding siblings ...)
  2023-04-05 20:16 ` mpolacek at gcc dot gnu.org
@ 2023-04-06 13:25 ` ppalka at gcc dot gnu.org
  2023-07-07 10:44 ` [Bug c++/107853] [11 " rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-04-06 13:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11/12 Regression]       |[10/11 Regression] variadic
                   |variadic template with a    |template with a variadic
                   |variadic template friend    |template friend with a
                   |with a requires of fold     |requires of fold expression
                   |expression                  |

--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13 and 12.3 so far

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

* [Bug c++/107853] [11 Regression] variadic template with a variadic template friend with a requires of fold expression
  2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
                   ` (10 preceding siblings ...)
  2023-04-06 13:25 ` [Bug c++/107853] [10/11 " ppalka at gcc dot gnu.org
@ 2023-07-07 10:44 ` rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

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

end of thread, other threads:[~2023-07-07 10:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 23:39 [Bug c++/107853] New: Cannot create friend function template with variadic pack that depends on variadic pack davidfromonline at gmail dot com
2022-11-24  1:04 ` [Bug c++/107853] Cannot create friend function template with a requires uses the " pinskia at gcc dot gnu.org
2022-11-24  1:09 ` [Bug c++/107853] [10/11/12/13 Regression] variadic template with a variadic template friend with a requires of fold expression pinskia at gcc dot gnu.org
2022-12-21  9:52 ` rguenth at gcc dot gnu.org
2022-12-21 16:09 ` ppalka at gcc dot gnu.org
2022-12-21 16:09 ` ppalka at gcc dot gnu.org
2022-12-21 16:10 ` ppalka at gcc dot gnu.org
2022-12-23 14:18 ` cvs-commit at gcc dot gnu.org
2022-12-23 14:19 ` [Bug c++/107853] [10/11/12 " ppalka at gcc dot gnu.org
2023-03-07  2:18 ` cvs-commit at gcc dot gnu.org
2023-04-05 20:16 ` mpolacek at gcc dot gnu.org
2023-04-06 13:25 ` [Bug c++/107853] [10/11 " ppalka at gcc dot gnu.org
2023-07-07 10:44 ` [Bug c++/107853] [11 " rguenth 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).