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

Peter Collingbourne peter at pcc.me.uk
Tue Sep 17 19:10:44 PDT 2013


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1705.1.patch
Type: text/x-patch
Size: 1345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130917/86ce4895/attachment.bin>


More information about the cfe-commits mailing list