public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108488] New: segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template
@ 2023-01-20 22:42 wendellcraigbaker at gmail dot com
  2023-01-20 22:47 ` [Bug c++/108488] " wendellcraigbaker at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: wendellcraigbaker at gmail dot com @ 2023-01-20 22:42 UTC (permalink / raw)
  To: gcc-bugs

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

            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=54320&action=edit
Complete C++ to exhibit the segfault

The sequence of declarations causes a segfault in gcc 12.2.1 under -fmodules-ts


template <typename> class k;
...more...
struct d {
  ...
  void ck(k<int> const &);
  void ck(int);
};
...more...
template <typename> class k {
  template <typename> friend class ca;
};
...more...
  auto e::operator+=(e &&cl) -> e & {
    for (auto bt : cl)
      ck(bt);
    return *this;
  }
...more...
template <typename> class ca {};
ca<int> d;



It is specific to -fmodules-ts
It is specific to the declaration of friend class ca introduced at class scope.

The exhibition and script show details.


The compiler instance here stock-delivered Fedora 37 GCC 12.2.1 but the problem
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,positionColumn:1,positionLineNumber:34,selectionStartColumn:1,selectionStartLineNumber:34,startColumn:1,startLineNumber:34),source:'class+e%3B%0A%0Atemplate+%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+const+%26)%3B%0A++void+ck(int)%3B%0A%7D%3B%0A%0A%0Aclass+e+:+d+%7B%0A++auto+operator%2B%3D(e+%26%26)+-%3E+e+%26%3B%0A%7D%3B%0Atemplate+%3Ctypename%3E+class+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+source+%231',t:'0')),k:27.194244604316548,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,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,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B23+-fmodules-ts',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber: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 <typename> 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 <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1

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

* [Bug c++/108488] segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template
  2023-01-20 22:42 [Bug c++/108488] New: segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template wendellcraigbaker at gmail dot com
@ 2023-01-20 22:47 ` wendellcraigbaker at gmail dot com
  2023-01-20 22:48 ` wendellcraigbaker at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: wendellcraigbaker at gmail dot com @ 2023-01-20 22:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Wendell Baker <wendellcraigbaker at gmail dot com> ---
Created attachment 54321
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54321&action=edit
run cc1plus to echigit the problem

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

* [Bug c++/108488] segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template
  2023-01-20 22:42 [Bug c++/108488] New: segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template wendellcraigbaker at gmail dot com
  2023-01-20 22:47 ` [Bug c++/108488] " wendellcraigbaker at gmail dot com
@ 2023-01-20 22:48 ` wendellcraigbaker at gmail dot com
  2023-01-21  2:35 ` wendellcraigbaker at gmail dot com
  2023-01-24  3:27 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: wendellcraigbaker at gmail dot com @ 2023-01-20 22:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Wendell Baker <wendellcraigbaker at gmail dot com> ---
Created attachment 54322
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54322&action=edit
exhibited output of run.sh showing the segfault with and without -fmodules-ts

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

* [Bug c++/108488] segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template
  2023-01-20 22:42 [Bug c++/108488] New: segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template wendellcraigbaker at gmail dot com
  2023-01-20 22:47 ` [Bug c++/108488] " wendellcraigbaker at gmail dot com
  2023-01-20 22:48 ` wendellcraigbaker at gmail dot com
@ 2023-01-21  2:35 ` wendellcraigbaker at gmail dot com
  2023-01-24  3:27 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: wendellcraigbaker at gmail dot com @ 2023-01-21  2:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Wendell Baker <wendellcraigbaker at gmail dot com> ---
Created attachment 54324
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54324&action=edit
shell script and C++ to demonstrate with <map> and <unordered_map> in
combination

This happens in real life with the confluence of <map> and <unordered_map> as
the accompanying exhibition highlights.

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

* [Bug c++/108488] segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template
  2023-01-20 22:42 [Bug c++/108488] New: segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template wendellcraigbaker at gmail dot com
                   ` (2 preceding siblings ...)
  2023-01-21  2:35 ` wendellcraigbaker at gmail dot com
@ 2023-01-24  3:27 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-24  3:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 104234.

*** This bug has been marked as a duplicate of bug 104234 ***

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

end of thread, other threads:[~2023-01-24  3:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-20 22:42 [Bug c++/108488] New: segfault with -fmodules-ts and class-scope friend declaration first in uninstantiated template wendellcraigbaker at gmail dot com
2023-01-20 22:47 ` [Bug c++/108488] " wendellcraigbaker at gmail dot com
2023-01-20 22:48 ` wendellcraigbaker at gmail dot com
2023-01-21  2:35 ` wendellcraigbaker at gmail dot com
2023-01-24  3:27 ` pinskia 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).