[Bug libstdc++/94960] New: extern template prevents inlining of standard library objects
krzysio.kurek at wp dot pl
gcc-bugzilla@gcc.gnu.org
Tue May 5 20:09:58 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94960
Bug ID: 94960
Summary: extern template prevents inlining of standard library
objects
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: krzysio.kurek at wp dot pl
Target Milestone: ---
Consider this example
void foo()
{
std::string(1, 0);
}
(https://godbolt.org/z/AlkBBJ)
This function creates a string using the `basic_string(size_t, CharT)`
constructor and then discards it. This particular constructor uses _M_construct
internally, which is declared as an out of line member function. Because of
this, and because the function isn't marked as `inline`, when the compiler
reaches the `extern template class basic_string<char>;`, it foregoes trying to
find the definition for _M_construct, instead generating a call to it, causing
foo() to fully instantiate a string object and then delete it, since the
compiler can't find _M_construct within its own translation unit.
This problem applies to every member function of any class which has an extern
template, is defined out of line and is not marked as `inline`.
More information about the Gcc-bugs
mailing list