[PATCH] Include explicit instantiations of iostream inserters and extractors in string.cpp.

Howard Hinnant howard.hinnant at gmail.com
Sat Sep 21 14:23:18 PDT 2013


Can you show a conforming example that demonstrates this problem?  My thinking has been that there is no way to use these functions in a conforming manner wtih including <{i,o}stream>.

Howard

On Sep 17, 2013, at 10:10 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:

> Any TU which calls one of these functions without also #including
> <{i,o}stream> will not receive a definition of the function.
> Without this change, this may lead to an undefined reference error
> at link time.
> 
> The standard wants us to define the functions in <string>.  However,
> this seems to be quite difficult due to mutual dependency issues.
> The best we can do is probably to instantiate the functions here,
> although this will mean that we will be nonconformant in the case
> where a custom allocator is being used.
> 
> http://llvm-reviews.chandlerc.com/D1705
> 
> Files:
>  src/string.cpp
> 
> Index: src/string.cpp
> ===================================================================
> --- src/string.cpp
> +++ src/string.cpp
> @@ -13,7 +13,9 @@
> #include "cstdlib"
> #include "cwchar"
> #include "cerrno"
> +#include "istream"
> #include "limits"
> +#include "ostream"
> #include "stdexcept"
> #ifdef _LIBCPP_MSVCRT
> #include "support/win32/support.h"
> @@ -527,4 +529,27 @@
> {
>     return as_string(get_swprintf(), initial_string<wstring, long double>()(), L"%Lf", val);
> }
> +
> +template istream &operator>>(istream &is, string &str);
> +template wistream &operator>>(wistream &is, wstring &str);
> +
> +template ostream &operator<<(ostream &is, const string &str);
> +template wostream &operator<<(wostream &is, const wstring &str);
> +
> +template istream &getline(istream &is, string &str, char delim);
> +template wistream &getline(wistream &is, wstring &str, wchar_t delim);
> +
> +template istream &getline(istream &is, string &str);
> +template wistream &getline(wistream &is, wstring &str);
> +
> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
> +
> +template istream &getline(istream &&is, string &str, char delim);
> +template wistream &getline(wistream &&is, wstring &str, wchar_t delim);
> +
> +template istream &getline(istream &&is, string &str);
> +template wistream &getline(wistream &&is, wstring &str);
> +
> +#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
> +
> _LIBCPP_END_NAMESPACE_STD
> <D1705.1.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list