public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "lh_mouse at 126 dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-109464-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109464 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=54824&action=edit unreduced testcase Attached is a preprocessed file. I don't know how to reduce it for absence of a function. ``` template<typename charT> class basic_shallow_string { static_assert(!is_array<charT>::value, "invalid character type"); static_assert(is_trivial<charT>::value, "characters must be trivial"); template<typename, typename> 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<char>; ``` And in 'cow_string.cpp' I have ``` #include "cow_string.hpp" namespace rocket { template class basic_shallow_string<char>; (... 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 references: ``` /usr/bin/ld: asteria/repl/bin_asteria-commands.o: in function `rocket::basic_shallow_string<char> rocket::sref<char>(char const*)': /home/lh_mouse/GitHub/asteria/asteria/repl/../../rocket/cow_string.hpp:97: undefined reference to `rocket::basic_shallow_string<char>::basic_shallow_string(char const*)' collect2: error: ld returned 1 exit status ``` This happens only with the constructor.
next reply other threads:[~2023-04-10 14:15 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-04-10 14:15 lh_mouse at 126 dot com [this message] 2023-04-10 20:50 ` [Bug c++/109464] " pinskia at gcc dot gnu.org 2023-04-11 3:50 ` lh_mouse at 126 dot com 2023-04-11 3:55 ` pinskia at gcc dot gnu.org 2023-04-11 4:44 ` lh_mouse at 126 dot com 2023-04-11 6:16 ` lh_mouse at 126 dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-109464-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).