From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3C3C73858425; Mon, 7 Feb 2022 20:17:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C3C73858425 From: "lhlaurini at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104433] New: [modules] Importing and using std::make_shared causes linker errors Date: Mon, 07 Feb 2022 20:17:08 +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: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lhlaurini at hotmail 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 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Feb 2022 20:17:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104433 Bug ID: 104433 Summary: [modules] Importing and using std::make_shared causes linker errors Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lhlaurini at hotmail dot com Target Milestone: --- Greetings. I found that by importing and trying to use std::make_shared, some symbols seem to not be defined. Example: $ cat main.cpp=20 import ; int main() { std::make_shared(); } $ g++ -v Using built-in specs. COLLECT_GCC=3Dg++ COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=3D/usr --libdir=3D/u= sr/lib --libexecdir=3D/usr/lib --mandir=3D/usr/share/man --infodir=3D/usr/share/in= fo --with-bugurl=3Dhttps://bugs.archlinux.org/ --enable-languages=3Dc,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl --with-linker-hash-style=3Dgnu --with-system-zlib --enable-__cxa_atexit --enable-cet=3Dauto --enable-checking=3Drelease --enable-clocale=3Dgnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build= -id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=3Dposix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=3D/usr/include/dlang/gdc Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.1.0 (GCC)=20 $ g++ -fmodules-ts -x c++-system-header memory $ g++ -fmodules-ts main.cpp=20 /usr/bin/ld: /tmp/ccezjsm1.o: in function `std::_Sp_make_shared_tag::_S_ti(= )': main.cpp:(.text._ZNSt19_Sp_make_shared_tag5_S_tiEv[_ZNSt19_Sp_make_shared_t= ag5_S_tiEv]+0x7): undefined reference to `std::_Sp_make_shared_tag::_S_ti()::__tag' collect2: error: ld returned 1 exit status $ g++-12 -v Using built-in specs. COLLECT_GCC=3Dg++-12 COLLECT_LTO_WRAPPER=3D/home/username/.local/stow/gcc/bin/../libexec/gcc/x86= _64-pc-linux-gnu/12.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc/configure --prefix=3D/home/username/.local --enable-languages=3Dc,c++ --disable-bootstrap --disable-multilib --with-system-zlib --program-suffix=3D-12 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.0.1 20220207 (experimental) (GCC) $ g++-12 -fmodules-ts -x c++-system-header memory $ g++-12 -fmodules-ts main.cpp=20 /usr/bin/ld: /tmp/cca9Gc2j.o: in function `std::_Sp_make_shared_tag::_S_ti(= )': main.cpp:(.text._ZNSt19_Sp_make_shared_tag5_S_tiEv[_ZNSt19_Sp_make_shared_t= ag5_S_tiEv]+0x5): undefined reference to `std::_Sp_make_shared_tag::_S_ti()::__tag' /usr/bin/ld: /tmp/cca9Gc2j.o: in function `std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count()': main.cpp:(.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev[_Z= NSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED5Ev]+0x23): undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()' collect2: error: ld returned 1 exit status As you can see the code fails on both gcc 11.1 (as packaged by Arch Linux) = and the latest gcc. There are more errors with the newer version, but these are caused by a change in libstdc++. >>From some quick investigation, I found that the errors seem to be occur when importing a header which either: 1. has a function that returns a static constexpr variable; 2. defines a member function of a class specialization outside the class template declaration (using inline or not). Additionally, I also found that defining a member function outside the (non-template) class declaration also causes the error, unless it's marked inline, but this problem doesn't seem to be directly triggered by . This is my attempt to create some simpler test cases for showing the bug(s): $ cat header.hpp struct A { static const int& f() { static constexpr int x =3D 0; return x; } }; struct B { static void f1(); static void f2(); }; void B::f1() { } // This is ok inline void B::f2() { } template struct C { static void f1(); static void f2(); }; template <> void C::f1() { } template <> inline void C::f2() { } $ cat main.cpp import "header.hpp"; int main() { A::f(); B::f1(); B::f2(); C::f1(); C::f2(); } $ g++ -fmodules-ts -x c++-header header.hpp=20 $ g++ -fmodules-ts main.cpp /usr/bin/ld: /tmp/ccMu0ee3.o: in function `main': main.cpp:(.text+0xa): undefined reference to `B::f1()' /usr/bin/ld: main.cpp:(.text+0x14): undefined reference to `C::f1()' /usr/bin/ld: main.cpp:(.text+0x19): undefined reference to `C::f2()' /usr/bin/ld: /tmp/ccMu0ee3.o: in function `A::f()': main.cpp:(.text._ZN1A1fEv[_ZN1A1fEv]+0x7): undefined reference to `A::f()::= x' collect2: error: ld returned 1 exit status $ g++-12 -fmodules-ts -x c++-header header.hpp=20 $ g++-12 -fmodules-ts main.cpp /usr/bin/ld: /tmp/ccpnyIWr.o: in function `main': main.cpp:(.text+0xa): undefined reference to `B::f1()' /usr/bin/ld: main.cpp:(.text+0x14): undefined reference to `C::f1()' /usr/bin/ld: main.cpp:(.text+0x19): undefined reference to `C::f2()' /usr/bin/ld: /tmp/ccpnyIWr.o: in function `A::f()': main.cpp:(.text._ZN1A1fEv[_ZN1A1fEv]+0x5): undefined reference to `A::f()::= x' collect2: error: ld returned 1 exit status=