From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9DA0D3858D20; Fri, 20 Jan 2023 22:42:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DA0D3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674254571; bh=iGh7RhLLSMuGMxoie22Niyt7g7PWTTZmbZS6voR6HvQ=; h=From:To:Subject:Date:From; b=VBX+wEUNBPqD3dGX7YmxX8lLep0gve8jF90aOjItIr0byIj6YcSUQgO+v/+KCOXHa WLylhZDc9lapHnBIS2z5eGSnDqsh3Sf9TMYuwKzSXUrA0FvfBRoY0OQ1rjQ7NDXyN/ yT/CVH/5HNuCKxVLDEqxa1z+7V+z2JLopH/VlADQ= From: "wendellcraigbaker at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108488] New: segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template Date: Fri, 20 Jan 2023 22:42:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: wendellcraigbaker at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108488 Bug ID: 108488 Summary: segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wendellcraigbaker at gmail dot com Target Milestone: --- Created attachment 54320 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54320&action=3Dedit Complete C++ to exhibit the segfault The sequence of declarations causes a segfault in gcc 12.2.1 under -fmodule= s-ts template class k; ...more... struct d { ... void ck(k const &); void ck(int); }; ...more... template class k { template friend class ca; }; ...more... auto e::operator+=3D(e &&cl) -> e & { for (auto bt : cl) ck(bt); return *this; } ...more... template class ca {}; ca d; It is specific to -fmodules-ts It is specific to the declaration of friend class ca introduced at class sc= ope. The exhibition and script show details. The compiler instance here stock-delivered Fedora 37 GCC 12.2.1 but the pro= blem exists in older versions and also on trunk. https://godbolt.org/z/GGP4dxnjY https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:= 14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:1,endLineNumber:34,p= ositionColumn:1,positionLineNumber:34,selectionStartColumn:1,selectionStart= LineNumber:34,startColumn:1,startLineNumber:34),source:'class+e%3B%0A%0Atem= plate+%3Ctypename%3E+class+k%3B%0A%0Astruct+l+%7B%0A++int+operator*()%3B%0A= ++void+operator%2B%2B()%3B%0A++friend+bool+operator%3D%3D(l,+l)%3B%0A%7D%3B= %0Astruct+d+%7B%0A++l+begin()%3B%0A++l+end()%3B%0A++void+ck(k%3Cint%3E+cons= t+%26)%3B%0A++void+ck(int)%3B%0A%7D%3B%0A%0A%0Aclass+e+:+d+%7B%0A++auto+ope= rator%2B%3D(e+%26%26)+-%3E+e+%26%3B%0A%7D%3B%0Atemplate+%3Ctypename%3E+clas= s+k+%7B%0A++template+%3Ctypename%3E+friend+class+ca%3B%0A%7D%3B%0A%0A++auto= +e::operator%2B%3D(e+%26%26cl)+-%3E+e+%26+%7B%0A++++for+(auto+bt+:+cl)%0A++= ++++ck(bt)%3B%0A++++return+*this%3B%0A++%7D%0A%0A%0Atemplate+%3Ctypename%3E= +class+ca+%7B%7D%3B%0A%0Aca%3Cint%3E+d%3B%0A'),l:'5',n:'0',o:'C%2B%2B+sourc= e+%231',t:'0')),k:27.194244604316548,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:ou= tput,i:(compilerName:'x86-64+clang+3.5',editorid:1,fontScale:14,fontUsePx:'= 0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+gcc+(trunk)+(Compiler+%231= )',t:'0')),header:(),k:47.805755395683455,l:'4',n:'0',o:'',s:0,t:'0'),(g:!(= (h:compiler,i:(compiler:gsnapshot,deviceViewOpen:'1',filters:(b:'0',binary:= '1',binaryObject:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1= ',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUs= ePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B23+-fmodules-ts',s= election:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1= ,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineN= umber:1),source:1),l:'5',n:'0',o:'+x86-64+gcc+(trunk)+(Editor+%231)',t:'0')= ),k:25,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4 On goldbolt.org, against trunk, the error messaging is: ' tree check: expected class 'type', have 'declaration' (type_decl) in get_originating_module_decl, at cp/module.cc:18634 32 | template class ca {}; | ^~ 0x23aef7e internal_error(char const*, ...) ???:0 0x939ce7 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*) ???:0 0xbc4c9b get_originating_module(tree_node*, bool) ???:0 0x23ce58c pp_format(pretty_printer*, text_info*) ???:0 0x23cf79d pp_format_verbatim(pretty_printer*, text_info*) ???:0 0x23cf885 pp_verbatim(pretty_printer*, char const*, ...) ???:0 0x23ad925 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info= *) ???:0 0x23aef7e internal_error(char const*, ...) ???:0 0x939ce7 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*) ???:0 0xbc4c9b get_originating_module(tree_node*, bool) ???:0 0xb6f28c decl_as_string(tree_node*, int) ???:0 0xb6f2c3 decl_as_dwarf_string(tree_node*, int) ???:0 0x1220e3c rest_of_type_compilation(tree_node*, int) ???:0 0xabf59e finish_struct_1(tree_node*) ???:0 0xca51c0 instantiate_class_template(tree_node*) ???:0 0xb258f3 start_decl_1(tree_node*, bool) ???:0 0xb48077 start_decl(cp_declarator const*, cp_decl_specifier_seq*, int, tree_node*, tree_node*, tree_node**) ???:0 0xc4e137 c_parse_file() ???:0 0xd89ad9 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 for instructions. Compiler returned: 1=