public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115616] New: Friend-injecting a template function causes an ICE if you inject after trying to instantiate that function
@ 2024-06-24 13:19 iamsupermouse at mail dot ru
  2024-06-25 20:39 ` [Bug c++/115616] c++20: " mpolacek at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: iamsupermouse at mail dot ru @ 2024-06-24 13:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115616
           Summary: Friend-injecting a template function causes an ICE if
                    you inject after trying to instantiate that function
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamsupermouse at mail dot ru
  Target Milestone: ---

The following causes an internal compiler error in GCC 14 and trunk:
https://gcc.godbolt.org/z/z9PWhWvzh

Same bug in Clang: https://github.com/llvm/llvm-project/issues/96485
MSVC compiles this successfully and calls `bar<10,20>()`.

    template <int X, int Y> void bar() {}

    template <typename T>
    struct Reader
    {
        template <int X>
        friend void foo(Reader<T>);
    };

    template <typename T, int Y>
    struct Writer
    {
        template <int X>
        friend void foo(Reader<T>) {bar<X, Y>();}
    };

    int main()
    {
        foo<10>(Reader<int>{});
        Writer<int, 20>{};
    }

GCC says: (this is trunk, v14 just says "segmentation fault")

    <source>: In instantiation of 'void foo(Reader<T>) [with int X = 10; T =
int; int Y = <missing>]':
    <source>:19:12:   required from here
     19 |     foo<10>(Reader<int>{});
        |     ~~~~~~~^~~~~~~~~~~~~~~
    <source>:14:33: internal compiler error: tree check: accessed elt 2 of
'tree_vec' with 1 elts in tsubst, at cp/pt.cc:16362
     14 |     friend void foo(Reader<T>) {bar<X, Y>();}
        |                                 ^~~~~~~~~
    0x26cfe8c internal_error(char const*, ...)
        ???:0
    0x97a4bb tree_vec_elt_check_failed(int, int, char const*, int, char const*)
        ???:0
    0xcbc689 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
    0xcabce3 instantiate_decl(tree_node*, bool, bool)
        ???:0
    0xcd625b instantiate_pending_templates(int)
        ???:0
    0xb6e830 c_parse_final_cleanups()
        ???:0
    0xdcad68 c_common_parse_file()
        ???:0

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

* [Bug c++/115616] c++20: Friend-injecting a template function causes an ICE if you inject after trying to instantiate that function
  2024-06-24 13:19 [Bug c++/115616] New: Friend-injecting a template function causes an ICE if you inject after trying to instantiate that function iamsupermouse at mail dot ru
@ 2024-06-25 20:39 ` mpolacek at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-06-25 20:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-06-25
             Status|UNCONFIRMED                 |ASSIGNED
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r9-3807-g5d9a0e3b99e31a

commit 5d9a0e3b99e31a2167f6b6ab2473feb58f7c77e8
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Nov 1 22:10:31 2018 +0000

    Implement P0846R0, ADL and function templates.

so apparently mine.

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

end of thread, other threads:[~2024-06-25 20:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-24 13:19 [Bug c++/115616] New: Friend-injecting a template function causes an ICE if you inject after trying to instantiate that function iamsupermouse at mail dot ru
2024-06-25 20:39 ` [Bug c++/115616] c++20: " mpolacek 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).