public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105761] New: ICE on hidden friend definition defined in base type
@ 2022-05-28 16:56 johelegp at gmail dot com
  2022-05-28 18:15 ` [Bug c++/105761] " johelegp at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: johelegp at gmail dot com @ 2022-05-28 16:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105761
           Summary: ICE on hidden friend definition defined in base type
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/v8arThEs1.

```C++
#include <type_traits>

template<class T> class X {
  friend auto f(X);
};

template<class T, class = std::void_t<>> struct downcast_t { using type = void;
};
template<class T> struct downcast_t<T, std::void_t<decltype(f(X<T>{}))>> {
using type = decltype(f(X<T>{})); };

template<class T> using downcast = typename downcast_t<T>::type;

static_assert(std::is_same_v<void, downcast<int>>);

struct Y : X<long> {
  friend auto f(X) { return 0L; }
};

static_assert(std::is_same_v<long, downcast<long>>);
```

```
<source>:4:18: warning: friend declaration 'auto f(X<T>)' declares a
non-template function [-Wnon-template-friend]
    4 |   friend auto f(X);
      |                  ^
<source>:4:18: note: (if this is not what you intended, make sure the function
template has already been declared and add '<>' after the function name here)
<source>:15:20: internal compiler error: in push_template_decl, at
cp/pt.cc:6125
   15 |   friend auto f(X) { return 0L; }
      |                    ^
0x21ffa39 internal_error(char const*, ...)
  ???:0
0x7452f3 fancy_abort(char const*, int, char const*)
  ???:0
0x82a0cd start_preparsed_function(tree_node*, tree_node*, int)
  ???:0
0x98cb8d c_parse_file()
  ???:0
0xb21d91 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.
```

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

* [Bug c++/105761] ICE on hidden friend definition defined in base type
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
@ 2022-05-28 18:15 ` johelegp at gmail dot com
  2022-05-30 10:04 ` [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341 marxin at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: johelegp at gmail dot com @ 2022-05-28 18:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
Simplified: https://godbolt.org/z/66Gd84dos.

```C++
template <class T>
class X {
  friend auto f(X);
};

struct Y : X<long> {
  friend auto f(X) { return 0L; }
};
```

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
  2022-05-28 18:15 ` [Bug c++/105761] " johelegp at gmail dot com
@ 2022-05-30 10:04 ` marxin at gcc dot gnu.org
  2022-06-03 16:27 ` jason at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-05-30 10:04 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ICE on hidden friend        |[11/12/13 Regression] ICE
                   |definition defined in base  |on hidden friend definition
                   |type                        |defined in base type since
                   |                            |r11-388-gc4bff4c230c8d341
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-05-30
                 CC|                            |marxin at gcc dot gnu.org,
                   |                            |nathan at gcc dot gnu.org

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r11-388-gc4bff4c230c8d341.

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
  2022-05-28 18:15 ` [Bug c++/105761] " johelegp at gmail dot com
  2022-05-30 10:04 ` [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341 marxin at gcc dot gnu.org
@ 2022-06-03 16:27 ` jason at gcc dot gnu.org
  2022-06-03 17:44 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2022-06-03 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
                   ` (2 preceding siblings ...)
  2022-06-03 16:27 ` jason at gcc dot gnu.org
@ 2022-06-03 17:44 ` cvs-commit at gcc dot gnu.org
  2022-06-03 18:12 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-03 17:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:284ae8b46f5eef74c0b660a87a7169497f559e73

commit r13-985-g284ae8b46f5eef74c0b660a87a7169497f559e73
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 3 12:35:12 2022 -0400

    c++: redeclared hidden friend [PR105761]

    Here, when we see the second declaration of f we match it with the first
    one, copy over DECL_TEMPLATE_INFO, and then try to use it when parsing the
    definition, leading to confusion.

            PR c++/105761

    gcc/cp/ChangeLog:

            * decl.cc (duplicate_decls): Don't copy DECL_TEMPLATE_INFO
            from a hidden friend.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/auto-fn64.C: New test.

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
                   ` (3 preceding siblings ...)
  2022-06-03 17:44 ` cvs-commit at gcc dot gnu.org
@ 2022-06-03 18:12 ` cvs-commit at gcc dot gnu.org
  2022-06-03 18:42 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-03 18:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:2843bfa21073dd1ac222540e189e8bcf40afc2c0

commit r12-8456-g2843bfa21073dd1ac222540e189e8bcf40afc2c0
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 3 12:35:12 2022 -0400

    c++: redeclared hidden friend [PR105761]

    Here, when we see the second declaration of f we match it with the first
    one, copy over DECL_TEMPLATE_INFO, and then try to use it when parsing the
    definition, leading to confusion.

            PR c++/105761

    gcc/cp/ChangeLog:

            * decl.cc (duplicate_decls): Don't copy DECL_TEMPLATE_INFO
            from a hidden friend.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/auto-fn64.C: New test.

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
                   ` (4 preceding siblings ...)
  2022-06-03 18:12 ` cvs-commit at gcc dot gnu.org
@ 2022-06-03 18:42 ` cvs-commit at gcc dot gnu.org
  2022-06-03 18:43 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-03 18:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

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

commit r11-10047-gc27cbeb985f7b6e1759399971b4fe2773e91ca71
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 3 12:35:12 2022 -0400

    c++: redeclared hidden friend [PR105761]

    Here, when we see the second declaration of f we match it with the first
    one, copy over DECL_TEMPLATE_INFO, and then try to use it when parsing the
    definition, leading to confusion.

            PR c++/105761

    gcc/cp/ChangeLog:

            * decl.c (duplicate_decls): Don't copy DECL_TEMPLATE_INFO
            from a hidden friend.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/auto-fn64.C: New test.

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
                   ` (5 preceding siblings ...)
  2022-06-03 18:42 ` cvs-commit at gcc dot gnu.org
@ 2022-06-03 18:43 ` jason at gcc dot gnu.org
  2022-06-08 20:38 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2022-06-03 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |11.3.1, 12.1.1, 13.0
   Target Milestone|---                         |11.4
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed.

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
                   ` (6 preceding siblings ...)
  2022-06-03 18:43 ` jason at gcc dot gnu.org
@ 2022-06-08 20:38 ` cvs-commit at gcc dot gnu.org
  2022-06-08 21:31 ` cvs-commit at gcc dot gnu.org
  2022-06-08 21:31 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-08 20:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

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

commit r13-1017-g7d87790a871482e9c5142a8e885b4a5f76d197c8
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 6 21:49:06 2022 -0400

    c++: redeclared hidden friend take 2 [PR105852]

    My previous patch for 105761 avoided copying DECL_TEMPLATE_INFO from a
    friend to a later definition, but in this testcase we have first a
    non-friend declaration and then a definition, and we need to avoid copying
    in that case as well.  But we do still want to set new_template_info to
    avoid GC trouble.

    With this change, the modules dump correctly identifies ::foo as a
    non-template function in tpl-friend-2_a.C.

    Along the way I noticed that the duplicate_decls handling of
    DECL_UNIQUE_FRIEND_P was backwards for templates, where we don't clobber
    DECL_LANG_SPECIFIC (olddecl) with DECL_LANG_SPECIFIC (newdecl) like we do
    for non-templates.

            PR c++/105852
            PR c++/105761

    gcc/cp/ChangeLog:

            * decl.cc (duplicate_decls): Avoid copying template info
            from non-templated friend even if newdecl isn't a definition.
            Correct handling of DECL_UNIQUE_FRIEND_P on templates.
            * pt.cc (non_templated_friend_p): New.
            * cp-tree.h (non_templated_friend_p): Declare it.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/tpl-friend-2_a.C: Adjust expected dump.
            * g++.dg/template/friend74.C: New test.

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
                   ` (7 preceding siblings ...)
  2022-06-08 20:38 ` cvs-commit at gcc dot gnu.org
@ 2022-06-08 21:31 ` cvs-commit at gcc dot gnu.org
  2022-06-08 21:31 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-08 21:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

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

commit r12-8467-ge057d454db4dcf48c22f75e57599f797d8e55baf
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 6 21:49:06 2022 -0400

    c++: redeclared hidden friend take 2 [PR105852]

    My previous patch for 105761 avoided copying DECL_TEMPLATE_INFO from a
    friend to a later definition, but in this testcase we have first a
    non-friend declaration and then a definition, and we need to avoid copying
    in that case as well.  But we do still want to set new_template_info to
    avoid GC trouble.

    With this change, the modules dump correctly identifies ::foo as a
    non-template function in tpl-friend-2_a.C.

    Along the way I noticed that the duplicate_decls handling of
    DECL_UNIQUE_FRIEND_P was backwards for templates, where we don't clobber
    DECL_LANG_SPECIFIC (olddecl) with DECL_LANG_SPECIFIC (newdecl) like we do
    for non-templates.

            PR c++/105852
            PR c++/105761

    gcc/cp/ChangeLog:

            * decl.cc (duplicate_decls): Avoid copying template info
            from non-templated friend even if newdecl isn't a definition.
            Correct handling of DECL_UNIQUE_FRIEND_P on templates.
            * pt.cc (non_templated_friend_p): New.
            * cp-tree.h (non_templated_friend_p): Declare it.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/tpl-friend-2_a.C: Adjust expected dump.
            * g++.dg/template/friend74.C: New test.

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

* [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341
  2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
                   ` (8 preceding siblings ...)
  2022-06-08 21:31 ` cvs-commit at gcc dot gnu.org
@ 2022-06-08 21:31 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-08 21:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:3e39a0a4b71dce674ee30fe71590b0152663b6d8

commit r11-10055-g3e39a0a4b71dce674ee30fe71590b0152663b6d8
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 6 21:49:06 2022 -0400

    c++: redeclared hidden friend take 2 [PR105852]

    My previous patch for 105761 avoided copying DECL_TEMPLATE_INFO from a
    friend to a later definition, but in this testcase we have first a
    non-friend declaration and then a definition, and we need to avoid copying
    in that case as well.  But we do still want to set new_template_info to
    avoid GC trouble.

    With this change, the modules dump correctly identifies ::foo as a
    non-template function in tpl-friend-2_a.C.

    Along the way I noticed that the duplicate_decls handling of
    DECL_UNIQUE_FRIEND_P was backwards for templates, where we don't clobber
    DECL_LANG_SPECIFIC (olddecl) with DECL_LANG_SPECIFIC (newdecl) like we do
    for non-templates.

            PR c++/105852
            PR c++/105761

    gcc/cp/ChangeLog:

            * decl.c (duplicate_decls): Avoid copying template info
            from non-templated friend even if newdecl isn't a definition.
            Correct handling of DECL_UNIQUE_FRIEND_P on templates.
            * pt.c (non_templated_friend_p): New.
            * cp-tree.h (non_templated_friend_p): Declare it.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/tpl-friend-2_a.C: Adjust expected dump.
            * g++.dg/template/friend74.C: New test.

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

end of thread, other threads:[~2022-06-08 21:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-28 16:56 [Bug c++/105761] New: ICE on hidden friend definition defined in base type johelegp at gmail dot com
2022-05-28 18:15 ` [Bug c++/105761] " johelegp at gmail dot com
2022-05-30 10:04 ` [Bug c++/105761] [11/12/13 Regression] ICE on hidden friend definition defined in base type since r11-388-gc4bff4c230c8d341 marxin at gcc dot gnu.org
2022-06-03 16:27 ` jason at gcc dot gnu.org
2022-06-03 17:44 ` cvs-commit at gcc dot gnu.org
2022-06-03 18:12 ` cvs-commit at gcc dot gnu.org
2022-06-03 18:42 ` cvs-commit at gcc dot gnu.org
2022-06-03 18:43 ` jason at gcc dot gnu.org
2022-06-08 20:38 ` cvs-commit at gcc dot gnu.org
2022-06-08 21:31 ` cvs-commit at gcc dot gnu.org
2022-06-08 21:31 ` cvs-commit 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).