[Bug libstdc++/86138] C++17: getline(istream, string) crashes on Cygwin because incompatible C++14 function is called
franke at computer dot org
gcc-bugzilla@gcc.gnu.org
Tue Jun 19 06:21:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86138
--- Comment #3 from Christian Franke <franke at computer dot org> ---
(In reply to Jonathan Wakely from comment #1)
> Why is the one in the DLL not compatible?
I don't know.
> The extern templates are disabled because std::basic_string has additional
> member functions in C++17 mode, and they're not instantiated in the library.
> By disabling the explicit instantiation declarations the compiler will emit
> definitions for the C++17-only member functions.
This has no effect due to the bogus specialization in basic_string.h (see patch
below).
> As requested at https://gcc.gnu.org/bugs testcases need to be provided here,
> not as URLs.
Sorry. New testcase below:
$ uname -srvmo
CYGWIN_NT-10.0 2.10.0(0.325/5/3) 2018-02-02 15:16 x86_64 Cygwin
$ g++ --version
g++ (GCC) 7.3.0
$ cygcheck -f /bin/cygstdc++-6.dll
libstdc++6-7.3.0-2
$ cat getlinetest.cpp
#include <sstream>
int main()
{
std::string line;
std::istringstream stream("*");
std::getline(stream, line, '\n');
return (int)line.c_str()[0];
}
$ g++ -o getlinetest getlinetest.cpp && ./getlinetest; echo $?
42
$ g++ -std=c++17 -o getlinetest getlinetest.cpp && ./getlinetest; echo $?
Aborted (core dumped)
134
$ g++ -std=c++17 -static -o getlinetest getlinetest.cpp && ./getlinetest;\
echo $?
42
Interestingly the statically linked version works. Is there possibly some
template function called by getline() which is not C++17 compatible? In the
static case the new version of this function from getline.o is used instead of
the old one in the lib*.a file.
Possible fix (char only, should also be done for wchar_t):
$ cat basic_string.h.patch
--- basic_string.h.orig 2018-05-03 06:22:46.000000000 +0200
+++ basic_string.h 2018-06-19 07:49:50.190322000 +0200
@@ -6329,11 +6329,6 @@
{ return std::getline(__is, __str); }
#endif
- template<>
- basic_istream<char>&
- getline(basic_istream<char>& __in, basic_string<char>& __str,
- char __delim);
-
#ifdef _GLIBCXX_USE_WCHAR_T
template<>
basic_istream<wchar_t>&
$ (cd /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits && patch) \
< basic_string.h.patch
patching file basic_string.h
$ g++ -std=c++17 -o getlinetest getlinetest.cpp && ./getlinetest; echo $?
42
More information about the Gcc-bugs
mailing list