public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Masamichi Hosoda <trueroad@trueroad.jp>
To: cygwin@cygwin.com
Subject: Re: [GCC] C++ program calling std::getline() crashes with certain compilation flags
Date: Thu, 06 Jul 2017 14:53:00 -0000	[thread overview]
Message-ID: <20170706.235307.636695868819506563.trueroad@trueroad.jp> (raw)
In-Reply-To: <80757ab8baa6434a8c56104c0ebfe803@Antiope.crf.canon.fr>

[-- Attachment #1: Type: Text/Plain, Size: 1137 bytes --]

> 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 test_getline.sh, 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 https://cygwin.com/ml/cygwin/2017-07/msg00088.html which appears to be circumvented by passing -std=gnu++11 instead of -std=c++11.

I've tried it with both cygwin-devel-2.8.0-1 and cygwin-devel-2.8.1-1.
With cygwin-devel-2.8.1-1, reproduced.
With cygwin-devel-2.8.0-1, there is no problem.

I've attached the script that I used and the results.

[-- Attachment #2: test_getline.sh --]
[-- Type: Application/Octet-Stream, Size: 616 bytes --]

cat <<EOF > test_getline.cxx
// Let's see if it works...
#include <iostream>
#include <string>
int main()
{
    std::string s;
    std::getline(std::cin, s);
    std::cout << "You entered \"" << s << "\".\n";
    return 0;
}
EOF

uname -a
apt-cyg show | grep "cygwin"
g++ --version

for std in c++98 c++03 c++11 c++14 c++17 gnu++98 gnu++03 gnu++11 gnu++14 gnu++17 ; do
    for opt in 0 1 2 3 ; do
        echo -n "### -std=${std} -O${opt} ###: "
        g++ -Wall -Wextra -std=${std} -O${opt} test_getline.cxx -o test_getline &&
            ./test_getline < test_getline.cxx
    done
done 2>&1 | sed 's| \{5,\}| |g'

[-- Attachment #3: test_getline_cygwin-devel-2.8.0-1.txt --]
[-- Type: Text/Plain, Size: 3227 bytes --]

CYGWIN_NT-10.0 Z87EXTREAM4 2.8.1(0.312/5/3) 2017-07-03 14:11 x86_64 Cygwin
base-cygwin                                   3.8-1
cygwin                                        2.8.1-1
cygwin-debuginfo                              2.8.1-1
cygwin-devel                                  2.8.0-1
g++ (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

### -std=c++98 -O0 ###: You entered "// Let's see if it works...".
### -std=c++98 -O1 ###: You entered "// Let's see if it works...".
### -std=c++98 -O2 ###: You entered "// Let's see if it works...".
### -std=c++98 -O3 ###: You entered "// Let's see if it works...".
### -std=c++03 -O0 ###: You entered "// Let's see if it works...".
### -std=c++03 -O1 ###: You entered "// Let's see if it works...".
### -std=c++03 -O2 ###: You entered "// Let's see if it works...".
### -std=c++03 -O3 ###: You entered "// Let's see if it works...".
### -std=c++11 -O0 ###: You entered "// Let's see if it works...".
### -std=c++11 -O1 ###: You entered "// Let's see if it works...".
### -std=c++11 -O2 ###: You entered "// Let's see if it works...".
### -std=c++11 -O3 ###: You entered "// Let's see if it works...".
### -std=c++14 -O0 ###: You entered "// Let's see if it works...".
### -std=c++14 -O1 ###: You entered "// Let's see if it works...".
### -std=c++14 -O2 ###: You entered "// Let's see if it works...".
### -std=c++14 -O3 ###: You entered "// Let's see if it works...".
### -std=c++17 -O0 ###: You entered "// Let's see if it works...".
### -std=c++17 -O1 ###: You entered "// Let's see if it works...".
### -std=c++17 -O2 ###: You entered "// Let's see if it works...".
### -std=c++17 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++98 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++98 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++98 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++98 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++03 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++03 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++03 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++03 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++11 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++11 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++11 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++11 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++14 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++14 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++14 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++14 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++17 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++17 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++17 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++17 -O3 ###: You entered "// Let's see if it works...".

[-- Attachment #4: test_getline_cygwin-devel-2.8.1-1.txt --]
[-- Type: Text/Plain, Size: 3933 bytes --]

CYGWIN_NT-10.0 Z87EXTREAM4 2.8.1(0.312/5/3) 2017-07-03 14:11 x86_64 Cygwin
base-cygwin                                   3.8-1
cygwin                                        2.8.1-1
cygwin-debuginfo                              2.8.1-1
cygwin-devel                                  2.8.1-1
g++ (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

### -std=c++98 -O0 ###: You entered "// Let's see if it works...".
### -std=c++98 -O1 ###: ./test_getline.sh: line 19: 20748 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++98 -O2 ###: ./test_getline.sh: line 19: 25148 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++98 -O3 ###: ./test_getline.sh: line 19:  8540 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++03 -O0 ###: You entered "// Let's see if it works...".
### -std=c++03 -O1 ###: ./test_getline.sh: line 19: 16156 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++03 -O2 ###: ./test_getline.sh: line 19: 12172 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++03 -O3 ###: ./test_getline.sh: line 19:   160 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++11 -O0 ###: You entered "// Let's see if it works...".
### -std=c++11 -O1 ###: ./test_getline.sh: line 19: 24840 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++11 -O2 ###: ./test_getline.sh: line 19: 12008 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++11 -O3 ###: ./test_getline.sh: line 19:  8140 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++14 -O0 ###: You entered "// Let's see if it works...".
### -std=c++14 -O1 ###: ./test_getline.sh: line 19:  7376 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++14 -O2 ###: ./test_getline.sh: line 19: 18080 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++14 -O3 ###: ./test_getline.sh: line 19: 22692 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++17 -O0 ###: You entered "// Let's see if it works...".
### -std=c++17 -O1 ###: ./test_getline.sh: line 19:  5796 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++17 -O2 ###: ./test_getline.sh: line 19: 24008 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=c++17 -O3 ###: ./test_getline.sh: line 19:  2844 Aborted (core dumped) ./test_getline < test_getline.cxx
### -std=gnu++98 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++98 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++98 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++98 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++03 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++03 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++03 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++03 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++11 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++11 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++11 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++11 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++14 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++14 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++14 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++14 -O3 ###: You entered "// Let's see if it works...".
### -std=gnu++17 -O0 ###: You entered "// Let's see if it works...".
### -std=gnu++17 -O1 ###: You entered "// Let's see if it works...".
### -std=gnu++17 -O2 ###: You entered "// Let's see if it works...".
### -std=gnu++17 -O3 ###: You entered "// Let's see if it works...".


[-- Attachment #5: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

      parent reply	other threads:[~2017-07-06 14:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-06 13:07 TANNHAUSER Falk
2017-07-06 14:21 ` Dan Kegel
2017-07-07 11:31   ` TANNHAUSER Falk
2017-07-13 12:01     ` TANNHAUSER Falk
2017-07-06 14:53 ` Masamichi Hosoda [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170706.235307.636695868819506563.trueroad@trueroad.jp \
    --to=trueroad@trueroad.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).