On 1 April 2015 at 16:09, Jonathan Wakely <jwakely(a)redhat.com> wrote:
On 01/04/15 15:16 +0100, Ian Malone wrote:
>
> Do you mind clarifying? I thought <string> should provide that
>
http://www.cplusplus.com/reference/string/string/operator+/ or is that
> what fno-implicit-templates is turning off?
Of course string provides it, but it's a template, so it needs to be
instantiated. The GCC manual documents -fno-implicit-templates like
so:
Never emit code for non-inline templates that are instantiated
implicitly (i.e. by use); only emit code for explicit
instantiations.
The invalid program in the OP uses operator+(), which would normally
instantiate the function template implicitly. But if you use
-fno-implicit-templates you are promising the compiler you will
provide explicit instantiations. The program above does not provide
them, so it is broken.
Thanks. Hadn't occurred to me the + operator here was a template as
I'd never had to deal with basic_string. Still a bit puzzled as
cplusplus.com says string is an instantiation of basic_string while
cppreference.com says it's a typedef (which I guess doesn't count as
explicit instantiation).
--
imalone
http://ibmalone.blogspot.co.uk