public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list
@ 2013-03-08  8:30 potswa at mac dot com
  2013-03-08  8:43 ` [Bug c++/56567] [4.8 Regression] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: potswa at mac dot com @ 2013-03-08  8:30 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56567
           Summary: ICE with lambda return type deduction and
                    braced-init-list
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: potswa@mac.com


#include <string>
#include <iostream>
#include <initializer_list>

int main() {
    for ( auto && s : []()
          { return { std::string( "first" ), std::string( "second" ) }; }() )
        std::cout << s << '\n';
}

ildtice.cpp: In lambda function:
ildtice.cpp:7:61: internal compiler error: in make_decl_rtl, at varasm.c:1136
  { return { std::string( "first" ), std::string( "second" ) }; }() )
                                                             ^

ildtice.cpp:7:61: internal compiler error: Abort trap: 6
g++: internal compiler error: Abort trap: 6 (program cc1plus)


C++11 5.1.2/4:
…
— if the compound-statement is of the form
{ attribute-specifier-seqopt return expression ; }
…

The return statement doesn't match the pattern because a braced-init-list is
not an expression. Should be a proper error.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list
  2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
@ 2013-03-08  8:43 ` jakub at gcc dot gnu.org
  2013-03-08 15:56 ` jason at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-03-08  8:43 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-03-08
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org
   Target Milestone|---                         |4.8.0
            Summary|ICE with lambda return type |[4.8 Regression] ICE with
                   |deduction and               |lambda return type
                   |braced-init-list            |deduction and
                   |                            |braced-init-list
     Ever Confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-03-08 08:42:43 UTC ---
Started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185768


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list
  2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
  2013-03-08  8:43 ` [Bug c++/56567] [4.8 Regression] " jakub at gcc dot gnu.org
@ 2013-03-08 15:56 ` jason at gcc dot gnu.org
  2013-03-08 16:14 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-08 15:56 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-08 15:55:28 UTC ---
Author: jason
Date: Fri Mar  8 15:55:18 2013
New Revision: 196548

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196548
Log:
    PR c++/56567
    * semantics.c (apply_deduced_return_type): Don't allow returning
    std::initializer_list.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list
  2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
  2013-03-08  8:43 ` [Bug c++/56567] [4.8 Regression] " jakub at gcc dot gnu.org
  2013-03-08 15:56 ` jason at gcc dot gnu.org
@ 2013-03-08 16:14 ` jason at gcc dot gnu.org
  2013-03-10  2:18 ` potswa at mac dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-08 16:14 UTC (permalink / raw)
  To: gcc-bugs


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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-08 16:13:53 UTC ---
Fixed.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list
  2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
                   ` (2 preceding siblings ...)
  2013-03-08 16:14 ` jason at gcc dot gnu.org
@ 2013-03-10  2:18 ` potswa at mac dot com
  2013-03-11  3:22 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: potswa at mac dot com @ 2013-03-10  2:18 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from David Krauss <potswa at mac dot com> 2013-03-10 02:18:18 UTC ---
Note, there is nothing in the Standard to prohibit return of an
initializer_list value, so this rejects programs which are conformant.

Unless/until #56568 is resolved, doing so results in UB (whether or not that's
a bug). That's only if the function is executed.

It's certainly legal to compile a function returning an std::initializer list,
which is never called. So this fix is problematic. For example

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

Not filing another report yet because I haven't pulled the changes and tested
anything for myself.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list
  2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
                   ` (3 preceding siblings ...)
  2013-03-10  2:18 ` potswa at mac dot com
@ 2013-03-11  3:22 ` jason at gcc dot gnu.org
  2013-03-11 16:23 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-11  3:22 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-11 03:21:52 UTC ---
(In reply to comment #4)
> It's certainly legal to compile a function returning an std::initializer list,
> which is never called. So this fix is problematic. For example
> 
> []{ return std::initializer_list< int >{ 1, 2 }; }();

That's a good point, though returning an initializer_list value is completely
useless; since the underlying array is local to the returning function, any use
of the returned value would cause undefined behavior, just like returning a
reference to a local variable.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list
  2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
                   ` (4 preceding siblings ...)
  2013-03-11  3:22 ` jason at gcc dot gnu.org
@ 2013-03-11 16:23 ` jason at gcc dot gnu.org
  2013-03-11 22:43 ` potswa at mac dot com
  2013-03-11 22:51 ` potswa at mac dot com
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-11 16:23 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-11 16:22:28 UTC ---
Author: jason
Date: Mon Mar 11 16:22:16 2013
New Revision: 196600

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196600
Log:
    PR c++/56567
    * typeck.c (check_return_expr): Disallow returning init list here.
    * semantics.c (apply_deduced_return_type): Not here.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list
  2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
                   ` (5 preceding siblings ...)
  2013-03-11 16:23 ` jason at gcc dot gnu.org
@ 2013-03-11 22:43 ` potswa at mac dot com
  2013-03-11 22:51 ` potswa at mac dot com
  7 siblings, 0 replies; 9+ messages in thread
From: potswa at mac dot com @ 2013-03-11 22:43 UTC (permalink / raw)
  To: gcc-bugs


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() } } );


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/56567] [4.8 Regression] ICE with lambda return type deduction and braced-init-list
  2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
                   ` (6 preceding siblings ...)
  2013-03-11 22:43 ` potswa at mac dot com
@ 2013-03-11 22:51 ` potswa at mac dot com
  7 siblings, 0 replies; 9+ messages in thread
From: potswa at mac dot com @ 2013-03-11 22:51 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #8 from David Krauss <potswa at mac dot com> 2013-03-11 22:51:12 UTC ---
Oops, I didn't see the preceding comment & checkin before submitting that.
Maybe that's a better place to check, but we might keep the extra test cases.
Make sure that the remaining ICE is gone.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-03-11 22:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-08  8:30 [Bug c++/56567] New: ICE with lambda return type deduction and braced-init-list potswa at mac dot com
2013-03-08  8:43 ` [Bug c++/56567] [4.8 Regression] " jakub at gcc dot gnu.org
2013-03-08 15:56 ` jason at gcc dot gnu.org
2013-03-08 16:14 ` jason at gcc dot gnu.org
2013-03-10  2:18 ` potswa at mac dot com
2013-03-11  3:22 ` jason at gcc dot gnu.org
2013-03-11 16:23 ` jason at gcc dot gnu.org
2013-03-11 22:43 ` potswa at mac dot com
2013-03-11 22:51 ` potswa at mac dot com

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