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.
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
Done.