This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[GCC] C++ program calling std::getline() crashes with certain compilation flags

The following C++ program crashes when compiled with GCC (both 5.4 and 6.3) under Cygwin, when compiled with both an optimization level higher than -O0 (i.e. -O1, -O2 or -O3) and the C++ standard set to -std=c++nn (for any supported nn, i.e. 98, 03, 11, 14 or 17):
#include <iostream>
#include <string>
int main()
    std::string s;
    std::getline(std::cin, s);
    std::cout << "You entered \"" << s << "\".\n";
    return 0;
On the other hand, when compiled with -std=gnu++nn or -O0, the program executes normally. For details, run the attached Bash script, which produces the output contained in the attached file test_getline_Cygwin.txt . No similar problem shows with GCC under Linux.
It looks similar to the problem reported in which appears to be circumvented by passing -std=gnu++11 instead of -std=c++11.
Under GDB, a faulty executable produces a message like:
Thread 1 "test_getline" received signal SIGABRT, Aborted.
0x00000003bf12576b in cygstdc++-6!_ZNSs7reserveEm () from /usr/bin/cygstdc++-6.dll
Un-mangling _ZNSs7reserveEm through c++filt gives
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long)


Attachment: test_getline_Cygwin.txt
Description: test_getline_Cygwin.txt


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]