Bug 50478 - [C++0x] Internal compiler error when using initializer lists
Summary: [C++0x] Internal compiler error when using initializer lists
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: 4.7.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-22 06:39 UTC by Matti Rintala
Modified: 2012-10-10 09:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.7.1, 4.8.0
Known to fail:
Last reconfirmed: 2011-09-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 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.
Comment 1 Daniel Krügler 2011-09-22 07:19:17 UTC
The problem seem to exist in 4.7.0 20110917 (experimental) as well, pointing to
joust, at cp/call.c:7960.
Comment 2 Paolo Carlini 2011-12-21 11:17:10 UTC
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>.
Comment 3 Paolo Carlini 2011-12-21 12:20:43 UTC
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"} );
}
Comment 4 Paolo Carlini 2011-12-21 12:43:38 UTC
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"} );
}
Comment 5 Paolo Carlini 2012-04-18 10:35:59 UTC
Seems fixed in mainline.
Comment 6 Paolo Carlini 2012-10-10 09:01:21 UTC
Fixed in 4.7.1 and mainline. Let's add the testcase and close the PR.
Comment 7 paolo@gcc.gnu.org 2012-10-10 09:12:28 UTC
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  <paolo.carlini@oracle.com>

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

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/initlist67.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 8 Paolo Carlini 2012-10-10 09:13:12 UTC
Done.