Quick C++ question for C++ experts :)

Ian Malone ibmalone at gmail.com
Wed Apr 1 14:16:35 UTC 2015


On 1 April 2015 at 14:32, Jonathan Wakely <jwakely at redhat.com> wrote:
> On 28/03/15 16:45 -0300, Paulo César Pereira de Andrade wrote:
>>
>> 2015-03-28 16:06 GMT-03:00 Paulo César Pereira de Andrade
>> <paulo.cesar.pereira.de.andrade at gmail.com>:
>>>
>>> Is this expected to not compile with -fno-implicit-templates?
>>>
>>> ---%<---
>>> $ cat test.cc
>>> #include <string>
>>> std::string test(int i)
>>> {
>>>     std::string t;
>>>     std::string s = "(";
>>>     t = "";
>>>     for (int r = i; r; r>>=1) {
>>>         if (r & 1)
>>>             t = "1" + t;
>>>         else
>>>             t = "0" + t;
>>>     }
>>>     s += t;
>>>     s += ")";
>>>     return s;
>>> }
>>>
>>> int
>>> main(int argc, char *argv[])
>>> {
>>>     std::string s = test(16);
>>>     return 0;
>>> }
>>>

> As I stated in the bug report, the code is invalid, but used to work
> due to an undocumented "accidental" feature of libstdc++.so which
> happens to provide instantiations of the required operator+().
>
> If you use -fno-implicit-templates then it is your responsibility to
> instantiate all the templates you use. The program uses operator+()
> without instantiating it, so the program is wrong. (It also uses a
> number of other templates without instantiating them, which is also
> wrong).
>

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?

-- 
imalone
http://ibmalone.blogspot.co.uk


More information about the devel mailing list