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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The problem seems to be explicit(bool), and it fails for gcc-11 too.

// header.h
template<typename _T1, typename _T2>
struct pair
{
        constexpr
      explicit(__is_same(_T1, _T2))
      pair()
      { }

        _T1 first;
        _T2 second;
};

struct string
{
  string() { }
  string(const char* s) : s(s) { }

  const char* s = "";
};

/home/jwakely/gcc/11/bin/g++ -std=c++2b -xc++-header header.h  -fmodules-ts


// crash.cpp
export module x;
import "header.h";
pair<string, string> environment;

/home/jwakely/gcc/11/bin/g++ -std=c++2b -c crash.cpp -fmodules-ts

In module ./header.h, imported at crash.cpp:2:
header.h: In instantiation of ‘struct pair<string, string>’:
crash.cpp:3:22:   required from here
header.h:6:7: internal compiler error: Segmentation fault
    6 |       pair()
      |       ^~~~
0xca8f1f crash_signal
        /home/jwakely/src/gcc/gcc-11/gcc/toplev.c:327
0x7fb52bd2d31f ???
        ../sysdeps/unix/sysv/linux/sigaction.c:670
0x7a3c23 hash_table_mod1(unsigned int, unsigned int)
        /home/jwakely/src/gcc/gcc-11/gcc/hash-table.h:344
0x7a3c23 hash_table<hash_map<tree_node*, tree_node*,
decl_tree_cache_traits>::hash_entry, false,
xcallocator>::find_with_hash(tree_node* const&, unsigned int)
        /home/jwakely/src/gcc/gcc-11/gcc/hash-table.h:911
0x7a3c23 hash_map<tree_node*, tree_node*,
decl_tree_cache_traits>::get(tree_node* const&)
        /home/jwakely/src/gcc/gcc-11/gcc/hash-map.h:185
0x7a3c23 lookup_explicit_specifier
        /home/jwakely/src/gcc/gcc-11/gcc/cp/pt.c:13782
0x7a3c23 tsubst_function_decl
        /home/jwakely/src/gcc/gcc-11/gcc/cp/pt.c:14007
0x799879 tsubst_decl
        /home/jwakely/src/gcc/gcc-11/gcc/cp/pt.c:14467
0x7ab3cc instantiate_class_template_1
        /home/jwakely/src/gcc/gcc-11/gcc/cp/pt.c:11997
0x7ac6a2 instantiate_class_template(tree_node*)
        /home/jwakely/src/gcc/gcc-11/gcc/cp/pt.c:12276
0x7de8db complete_type(tree_node*)
        /home/jwakely/src/gcc/gcc-11/gcc/cp/typeck.c:143
0x7de8db complete_type(tree_node*)
        /home/jwakely/src/gcc/gcc-11/gcc/cp/typeck.c:111
0x69c6eb start_decl_1(tree_node*, bool)
        /home/jwakely/src/gcc/gcc-11/gcc/cp/decl.c:5644
0x6ad5af start_decl(cp_declarator const*, cp_decl_specifier_seq*, int,
tree_node*, tree_node*, tree_node**)
        /home/jwakely/src/gcc/gcc-11/gcc/cp/decl.c:5610
0x76c443 cp_parser_init_declarator
        /home/jwakely/src/gcc/gcc-11/gcc/cp/parser.c:21763
0x74b124 cp_parser_simple_declaration
        /home/jwakely/src/gcc/gcc-11/gcc/cp/parser.c:14467
0x774e25 cp_parser_declaration
        /home/jwakely/src/gcc/gcc-11/gcc/cp/parser.c:14164
0x775afe cp_parser_toplevel_declaration
        /home/jwakely/src/gcc/gcc-11/gcc/cp/parser.c:14193
0x775afe cp_parser_translation_unit
        /home/jwakely/src/gcc/gcc-11/gcc/cp/parser.c:4942
0x775afe c_parse_file()
        /home/jwakely/src/gcc/gcc-11/gcc/cp/parser.c:45340
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.


The only reason you don't see it for gcc-11 is that <string> doesn't use
explicit(bool) until gcc-12.

I think the short answer for now is that compiling libstdc++ headers as header
units is not really supported.

Reply via email to