From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 72BA13857735; Mon, 10 Apr 2023 14:15:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72BA13857735 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681136140; bh=kHzoy9wtce4f3/n1Yzc4WeF4MJAJuKgDeSAG1RK/oks=; h=From:To:Subject:Date:From; b=w1H3H8ABRt8bbnjyu9fw7ku3eTHpi8yoKLPfOpG35P1KucHB8rWPW7aThZWsbHN0G aIExkhthuLD+CYuJHtbOL5xPQa2l9IQaUiIWGW4nLrUYWUl6BxTk97dCmxEeBJKO3H uHLPExvS7FY2ixhc5QtO8FIf5aj7oqJJZzb6LWGc= From: "lh_mouse at 126 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109464] New: gcc does not instantiate constructor for explicitly instantiated template Date: Mon, 10 Apr 2023 14:15:39 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lh_mouse at 126 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 attachments.created 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109464 Bug ID: 109464 Summary: gcc does not instantiate constructor for explicitly instantiated template Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lh_mouse at 126 dot com Target Milestone: --- Created attachment 54824 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54824&action=3Dedit unreduced testcase Attached is a preprocessed file. I don't know how to reduce it for absence = of a function. ``` template class basic_shallow_string { static_assert(!is_array::value, "invalid character type"); static_assert(is_trivial::value, "characters must be trivial"); template friend class basic_cow_string; private: const charT* m_ptr; size_t m_len; public: explicit constexpr basic_shallow_string(const charT* ptr) noexcept : m_ptr(ptr), m_len(noadl::xstrlen(ptr)) { } public: constexpr const charT* c_str() const noexcept { return this->m_ptr; } constexpr size_t length() const noexcept { return this->m_len; } (... more member functions follow ...) }; extern template class basic_shallow_string; ``` And in 'cow_string.cpp' I have=20 ``` #include "cow_string.hpp" namespace rocket { template class basic_shallow_string; (... more explicit instantiations follow ...) } // namespace rocket ``` This explicit instantiation instantiates all inline member functions above,= but not the constructor. I have examined assembly output, and there is no constructor. Unless optimization is enabled, this causes undefined referenc= es: ``` /usr/bin/ld: asteria/repl/bin_asteria-commands.o: in function `rocket::basic_shallow_string rocket::sref(char const*)': /home/lh_mouse/GitHub/asteria/asteria/repl/../../rocket/cow_string.hpp:97: undefined reference to `rocket::basic_shallow_string::basic_shallow_string(char const*)' collect2: error: ld returned 1 exit status ``` This happens only with the constructor.=