[Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list

potswa at mac dot com gcc-bugzilla@gcc.gnu.org
Mon Mar 11 22:43:00 GMT 2013


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

--- Comment #7 from David Krauss <potswa at mac dot com> 2013-03-11 22:42:46 UTC ---
Created attachment 29647
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29647
alternative fix

Yes. However, the above fix doesn't catch all instances of doing so; for
example

[]() -> std::initializer_list< int >{ return { 1, 2 }; }

Worse, one case still results in ICE

[]() { return std::initializer_list< int >{ 1, 2 }; }

Here's an improved fix. It doesn't attempt to catch runtime UB. I think that
should be another warning diagnostic, which can also flag such attempted
workarounds as reference return types

[]() -> std::initializer_list< int > && { return { 1, 2 }; }

Users are likely to try fiddling after we flag their initial attempt, so we
might as well be as broad as possible. However, a specialization of std::min
can return a valid std::initializer_list< T > const & :

struct s {
    friend bool operator < ( s lhs, s rhs ) { return false; }

    friend bool operator < ( std::initializer_list< s > lhs,
                             std::initializer_list< s > rhs )
        { return std::lexicographical_compare( lhs.begin(), lhs.end(),
                                               rhs.begin(), rhs.end() ); }
};

std::min( std::initializer_list< std::initializer_list< s > >
                                 { { s(), s(), s() }, { s(), s() } } );



More information about the Gcc-bugs mailing list