From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0A9BD385840F; Mon, 25 Jul 2022 16:37:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A9BD385840F From: "fxcoudert at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/106435] New: constructor of thread_local static member is not called Date: Mon, 25 Jul 2022 16:37:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fxcoudert at gcc dot gnu.org 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, 25 Jul 2022 16:37:06 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106435 Bug ID: 106435 Summary: constructor of thread_local static member is not called Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: fxcoudert at gcc dot gnu.org Target Milestone: --- Originally reported to Homebrew at https://github.com/Homebrew/homebrew-core/issues/105022 $ cat foo.hpp=20 #pragma once struct Foo { Foo(); void func(); }; struct Bar { thread_local static Foo foo; }; $ cat foo.cpp=20 #include "foo.hpp" #include Foo::Foo() { std::cout << "Foo::Foo(this=3D" << this << ")\n"; } void Foo::func() { std::cout << "Foo::func(this=3D" << this << ")\n"; } thread_local Foo Bar::foo; $ cat main.cpp=20 #include "foo.hpp" int main() { Bar::foo.func(); } Compiled with clang, the constructor is called. Compiled with gcc 11 or 12 = on aarch64-apple-darwin21, it is not: $ g++-12 -std=3Dc++17 foo.cpp main.cpp && ./a.out=20=20=20=20=20=20=20=20= =20=20=20 Foo::func(this=3D0x6000009e0038) $ g++-11 -std=3Dc++17 foo.cpp main.cpp && ./a.out Foo::func(this=3D0x600001418038) $ clang++ -std=3Dc++17 foo.cpp main.cpp && ./a.out Foo::Foo(this=3D0x60000209c000) Foo::func(this=3D0x60000209c000) $ g++-12 -v=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 Using built-in specs. COLLECT_GCC=3Dg++-12 COLLECT_LTO_WRAPPER=3D/opt/homebrew/Cellar/gcc@12/12.1.0_1/bin/../libexec/g= cc/aarch64-apple-darwin21/12/lto-wrapper Target: aarch64-apple-darwin21 Configured with: ../configure --prefix=3D/opt/homebrew/opt/gcc@12 --libdir=3D/opt/homebrew/opt/gcc@12/lib/gcc/12 --disable-nls --enable-checking=3Drelease --with-gcc-major-version-only --enable-languages=3Dc,c++,objc,obj-c++,fortran --program-suffix=3D-12 --with-gmp=3D/opt/homebrew/opt/gmp --with-mpfr=3D/opt/homebrew/opt/mpfr --with-mpc=3D/opt/homebrew/opt/libmpc --with-isl=3D/opt/homebrew/opt/isl --with-zstd=3D/opt/homebrew/opt/zstd --with-pkgversion=3D'Homebrew GCC 12.1= .0_1' --with-bugurl=3Dhttps://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=3Daarch64-apple-darwin21 --with-native-system-header-dir=3D/usr/include --with-sysroot=3D/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.1.0 (Homebrew GCC 12.1.0_1)=