[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#994292: g++-11: Segfault when defining a module exporting a std::string



Package: g++-11
Version: 11.2.0-4
Severity: normal

Dear Maintainer,

   * What led up to the situation?

When defining a simple module in which a std::string is exported the program
compiles correctly but segfaults when it's run. When (instead of a
std::string) objects like std::vector<double> or std::ifstream are exported
the segfault isn't observed.

   * What exactly did you do (or not do) that was effective (or
     ineffective)?

I defined the following module (mod.cc):

    module;
    
    #include <string>
    
    export module mod;
    
    export std::string modstr{ "hello" };

and the source file (main.cc) defining main():

    #include <iostream>
    
    import mod;
    
    int main()
    {
        std::cout << modstr << '\n';
    }

These files were compiled and linked calling:

    g++  --std=c++20 -Wall -O2  -fmodules-ts  -c -o mod.o mod.cc
    g++  --std=c++20 -Wall -O2  -fmodules-ts  -c -o main.o main.cc
    g++  main.o mod.o


   * What was the outcome of this action?

Compilation and linking succeeded, but when calling ./a.out the output was:

    Segmentation fault


   * What outcome did you expect instead?

Output to the std output stream of the line

    hello

Additional information: 

    When defining and exporting (and using in main()), e.g., 
std:vector<double> array{ 1, 2, 3 }  or  std::ifstream str{ "mod.cc } no
segfault was observed. 

    I found GCC Bugzilla – Bug 99569, where a module exports a function
returning a std::string, which program also segfaults, but apparently the
segfault is already encountered when defining a plain std::string module
object, and doesn't require an exported function

-- System Information:
Debian Release: bookworm/sid
  APT prefers testing
  APT policy: (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 5.10.0-8-amd64 (SMP w/4 CPU threads)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:en
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages g++-11 depends on:
ii  gcc-11            11.2.0-4
ii  gcc-11-base       11.2.0-4
ii  libc6             2.31-17
ii  libgmp10          2:6.2.1+dfsg-1
ii  libisl23          0.23-1
ii  libmpc3           1.2.0-1
ii  libmpfr6          4.1.0-3
ii  libstdc++-11-dev  11.2.0-4
ii  libzstd1          1.4.8+dfsg-2.1
ii  zlib1g            1:1.2.11.dfsg-2

g++-11 recommends no packages.

Versions of packages g++-11 suggests:
pn  g++-11-multilib  <none>
pn  gcc-11-doc       <none>

-- no debconf information

Reply to: