[C++0x] Internal compiler error when using initializer lists

Bug #1352356 reported by Jan Blechta on 2014-08-04
22
This bug affects 3 people
Affects Status Importance Assigned to Milestone
FEniCS Project
Undecided
Unassigned
gcc
Fix Released
Medium
gcc-4.6 (Ubuntu)
Undecided
Unassigned

Bug Description

From https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50478
 Matti Rintala 2011-09-22 06:39:46 UTC

The following short program shows the problem:

#include <set>
#include <string>

int main() {
    std::set<std::string> s;
    s.insert( {"abc", "def", "hij"} ); // This line is the problem
}

> g++ -std=c++0x test.cc
test.cc: In function ‘int main()’:
test.cc:6:37: internal compiler error: in joust, at cp/call.c:7646

If I compile with -pedantic, the program compiles fine.

In , Bitti (bitti) wrote :

The following short program shows the problem:

#include <set>
#include <string>

int main() {
    std::set<std::string> s;
    s.insert( {"abc", "def", "hij"} ); // This line is the problem
}

> g++ -std=c++0x test.cc
test.cc: In function ‘int main()’:
test.cc:6:37: internal compiler error: in joust, at cp/call.c:7646

If I compile with -pedantic, the program compiles fine.

The problem seem to exist in 4.7.0 20110917 (experimental) as well, pointing to
joust, at cp/call.c:7960.

Insane, this doesn't happen for an initializer list of 1, 2, 4, or 5 elements. Happens with std::vector too, however. Should be rather easy to construct a reduced testcase including only <string>.

This is enough:

namespace std
{
  template<class _E>
    class initializer_list;

  template<typename _Key>
    struct set
    {
      void insert(const _Key&);
    };

  struct string
  {
    string(const string&, __SIZE_TYPE__, __SIZE_TYPE__ = -1);
    string(const char*);
    string(initializer_list<char>);
  };
}

int main()
{
  std::set<std::string> s;
  s.insert( { "abc", "def", "hij"} );
}

This is a more correct testcase, which also preserves the property of OT that -pedantic works around the issue. Note: removing the string constructor taking an initializer_list also works around the problem:

///////////////////

#include <initializer_list>

namespace std
{
  template<typename _Key>
    struct set
    {
      void insert(const _Key&);
      void insert(initializer_list<_Key>);
    };

  struct string
  {
    string(const string&, __SIZE_TYPE__, __SIZE_TYPE__ = -1);
    string(const char*);
    string(initializer_list<char>);
  };
}

int main()
{
  std::set<std::string> s;
  s.insert( { "abc", "def", "hij"} );
}

Seems fixed in mainline.

Fixed in 4.7.1 and mainline. Let's add the testcase and close the PR.

In , Paolo-k (paolo-k) wrote :

Author: paolo
Date: Wed Oct 10 09:12:19 2012
New Revision: 192295

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192295
Log:
2012-10-10 Paolo Carlini <email address hidden>

 PR c++/50478
 * g++.dg/cpp0x/initlist67.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/initlist67.C
Modified:
    trunk/gcc/testsuite/ChangeLog

Jan Blechta (blechta) on 2014-08-04
affects: dolfin → fenics
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gcc-4.6 (Ubuntu):
status: New → Confirmed
Changed in gcc:
importance: Unknown → Medium
status: Unknown → Fix Released
Jan Blechta (blechta) on 2014-08-10
tags: added: precise
Matthias Klose (doko) wrote :

won't fix for GCC 4.6. you can find backports of newer compilers in the ubuntu-toolchain-r/test PPA.

Changed in gcc-4.6 (Ubuntu):
status: Confirmed → Won't Fix
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.