https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94960
Erich Keane <erich.keane at intel dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |erich.keane at intel dot com
--- Comment #3 from Erich Keane <erich.keane at intel dot com> ---
(In reply to Jonathan Wakely from comment #2)
> Please provide complete testcases, not just URLs, as required by
> https://gcc.gnu.org/bugs
>
> #include <string>
>
> int main()
> {
> std::string(size_t(0), 0);
> }
>
>
> I still think it's wrong for GCC to treat the 'inline' specifier as an
> inlining hint. The compiler should be a better judge of inlining decisions
> than the developer.
>
> (In reply to Andrew Pinski from comment #1)
> > g:1a289fa36294627c252492e4c18d7877a7c80dc1 changed that.
>
> Well that commit just meant that the explicit instantiations are declared
> for C++17 as well, where previously they were only declared for < C++17. It
> didn't add the explicit instantiations.
Hi Jon!
I helped the submitter in #llvm debug this a little, so I perhaps have a better
understanding of his issue:
As you know, "extern template" is a hint to the compiler that we don't need to
emit the template as a way to save on compile time.
Both GCC and clang will NOT instantiate these templates in O0 mode. However,
in O1+ modes, both will actually still instantiate the templates in the
frontend, BUT only for 'inline' functions. Basically, we're using 'inline' as
a heuristic that there is benefit in sending these functions to the optimizer
(basically, sacrificing the compile time gained by 'extern template' in
exchange for a better inlining experience).
In the submitter's case, the std::string constructor calls "_M_construct". The
constructor is inlined, but _M_construct is not, since it never gets to the
optimizer.
libc++ uses an __init function to do the same thing as _M_construct, however IT
is marked inline, and thus doesn't have the problem.
I believe the submitter wants to have you mark more of the functions in
extern-templated classes 'inline' so that it matches the heuristic better.
I don't think that there is a good way to change the compiler itself without
making 'extern template' absolutely meaningless.