public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "danny.dyk@tu-dortmund.de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/50015] New: std::initializer_list<std::string> members are not properly initialized
Date: Sun, 07 Aug 2011 15:48:00 -0000	[thread overview]
Message-ID: <bug-50015-4@http.gcc.gnu.org/bugzilla/> (raw)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50015

           Summary: std::initializer_list<std::string> members are not
                    properly initialized
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: danny.dyk@tu-dortmund.de


Created attachment 24940
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24940
Output of 'g++ -std=c++0x -save-temps -o test-case test-case.cc'

When creating a std::initializer_list<std::string> as part of a struct, the
actual
object is not properly initialized. Consider the following test case:

-- BEGIN --
#include <initializer_list>
#include <iostream>
#include <string>

struct T
{
    std::initializer_list<std::string> s;
};

T foo
{
    {"foo", "bar", "baz"}
};

int main(int, char**)
{
    for (auto t = foo.s.begin(), t_end = foo.s.end() ; t != t_end ; ++t)
        std::cout << *t << std::endl;

    return 0;
}
-- END --

After compiling this test case using

  g++ -Wall -pedantic -std=c++0x -o test-case test-case.cc
  [no errors, no warnings]

the execution of the resulting binary via

  ./test-case

either raises a segmentation fault or produces garbled output, e.g.,

  foo1`particularÿÿÿÿbar1ÿÿ

Looks very much like terminating '\0's are not in place.

This bug was first seen when using gcc-4.4.5 and is reproducable under
gcc-4.5.0
up to gcc-4.6.1. The particular version of gcc-4.6.1 was configured as

 configure \
    --prefix=/het/packages/gcc-${VERSION} \
    --program-prefix=het- \
    --program-suffix=-${VERSION} \
    --enable-languages=c,c++ \
    --disable-multilib

and built on an amd64 system.

I will attach the output of

  g++ -std=c++0x -save-temps -o test-case test-case.cc
  g++ -std=c++0x -fdump-tree-gimple -o test-case test-case.cc

to this bug report.

Thank you to Alexander Faeroey for help in reducing the segfaulting code to
a manageable test case.


             reply	other threads:[~2011-08-07 15:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-07 15:48 danny.dyk@tu-dortmund.de [this message]
2011-08-07 15:50 ` [Bug c++/50015] " danny.dyk@tu-dortmund.de
2011-08-07 16:38 ` [Bug c++/50015] [C++0x] " paolo.carlini at oracle dot com
2011-08-08 13:55 ` jason at gcc dot gnu.org
2011-11-04 16:26 ` jason at gcc dot gnu.org

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=bug-50015-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).