public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50431] New: lambda bug for array size def
@ 2011-09-16 11:41 zhudiqi at 163 dot com
  2011-09-16 11:51 ` [Bug c++/50431] " zhudiqi at 163 dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: zhudiqi at 163 dot com @ 2011-09-16 11:41 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50431
           Summary: lambda bug for array size def
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: zhudiqi@163.com


This code is OK,
OK:
  constexpr auto sz = []()->long { return 100L; };
  int arr1[sz()];

  int arr2[[]()->long { return 100L; }()];

But these code will failed for g++ compiler 4.6.1.

BUG1:
  auto sz = []()->constexpr long { return 100L; };
  int arr[[]()->long { return 100L; }];

BUG2:
  //feature.cpp:51:38: internal compiler error: Segmentation fault
  int arr[[]()->long { return 100L; }];


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

* [Bug c++/50431] lambda bug for array size def
  2011-09-16 11:41 [Bug c++/50431] New: lambda bug for array size def zhudiqi at 163 dot com
@ 2011-09-16 11:51 ` zhudiqi at 163 dot com
  2011-09-16 12:05 ` zhudiqi at 163 dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zhudiqi at 163 dot com @ 2011-09-16 11:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from zhudiqi at 163 dot com 2011-09-16 11:36:15 UTC ---
Created attachment 25304
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25304
lambda for array size def


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

* [Bug c++/50431] lambda bug for array size def
  2011-09-16 11:41 [Bug c++/50431] New: lambda bug for array size def zhudiqi at 163 dot com
  2011-09-16 11:51 ` [Bug c++/50431] " zhudiqi at 163 dot com
@ 2011-09-16 12:05 ` zhudiqi at 163 dot com
  2011-09-16 12:45 ` [Bug c++/50431] [C++0x] bug in def array size with a lambda redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zhudiqi at 163 dot com @ 2011-09-16 12:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from zhudiqi at 163 dot com 2011-09-16 11:40:42 UTC ---
BUG1:
  auto sz = []()->constexpr long { return 100L; };
  int arr[sz()];

Why constexpr for lambda won't be compiled? Can i not use auto type for a
lambda variant?


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

* [Bug c++/50431] [C++0x] bug in def array size with a lambda
  2011-09-16 11:41 [Bug c++/50431] New: lambda bug for array size def zhudiqi at 163 dot com
  2011-09-16 11:51 ` [Bug c++/50431] " zhudiqi at 163 dot com
  2011-09-16 12:05 ` zhudiqi at 163 dot com
@ 2011-09-16 12:45 ` redi at gcc dot gnu.org
  2011-09-16 14:01 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-09-16 12:45 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
      Known to work|                            |4.7.0
           Keywords|                            |error-recovery,
                   |                            |ice-on-invalid-code
   Last reconfirmed|                            |2011-09-16
                 CC|                            |jason at gcc dot gnu.org
     Ever Confirmed|0                           |1
            Summary|bug in def array size with  |[C++0x] bug in def array
                   |a lambda                    |size with a lambda
      Known to fail|                            |4.6.1
           Severity|major                       |normal

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-09-16 11:50:50 UTC ---
This is not "major" severity because the code is invalid, so it's just error
handling.

(In reply to comment #0)
> BUG1:
>   auto sz = []()->constexpr long { return 100L; };

This is invalid, constexpr is not part of the return type, it's a function
specifier.  G++ correctly rejects it.  The "bailing out" is due to the next
line:

>   int arr[[]()->long { return 100L; }];

This is also invalid, but shouldn't cause an ICE, and 4.7 doesn't get an ICE
here:

l.cc:2:38: error: size of array 'arr' has non-integral type '<lambda()>'

4.6.1 segfaults here:
Program received signal SIGSEGV, Segmentation fault.
compute_array_index_type (name=0x2aaaaac1e738, size=0x0, complain=3)
    at ../../gcc-4.6.1/gcc/cp/decl.c:7561
7561                  type = TREE_TYPE (size);
(gdb) bt
#0  compute_array_index_type (name=0x2aaaaac1e738, size=0x0, complain=3)
    at ../../gcc-4.6.1/gcc/cp/decl.c:7561
#1  0x00000000004ab611 in create_array_type_for_decl (declarator=0x1327be0,
    declspecs=0x7fffffffe1c0, decl_context=NORMAL, initialized=0,
    attrlist=0x7fffffffe0c8) at ../../gcc-4.6.1/gcc/cp/decl.c:7825


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

* [Bug c++/50431] [C++0x] bug in def array size with a lambda
  2011-09-16 11:41 [Bug c++/50431] New: lambda bug for array size def zhudiqi at 163 dot com
                   ` (2 preceding siblings ...)
  2011-09-16 12:45 ` [Bug c++/50431] [C++0x] bug in def array size with a lambda redi at gcc dot gnu.org
@ 2011-09-16 14:01 ` redi at gcc dot gnu.org
  2011-11-05 21:33 ` paolo.carlini at oracle dot com
  2011-11-13 13:09 ` zhudiqi at 163 dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-09-16 14:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-09-16 13:47:49 UTC ---
(In reply to comment #2)
> BUG1:
>   auto sz = []()->constexpr long { return 100L; };
>   int arr[sz()];
> 
> Why constexpr for lambda won't be compiled? Can i not use auto type for a
> lambda variant?

The closure type's function call operator can be const but not constexpr.
You can use auto for a lambda, you just can't have a constexpr lambda.

Why do you want it to work?  

What advantage is there to using a lambda instead of named function? e.g.

  constexpr long sz() { return 100L; };
  int arr[sz()];


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

* [Bug c++/50431] [C++0x] bug in def array size with a lambda
  2011-09-16 11:41 [Bug c++/50431] New: lambda bug for array size def zhudiqi at 163 dot com
                   ` (3 preceding siblings ...)
  2011-09-16 14:01 ` redi at gcc dot gnu.org
@ 2011-11-05 21:33 ` paolo.carlini at oracle dot com
  2011-11-13 13:09 ` zhudiqi at 163 dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-11-05 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-11-05 21:33:07 UTC ---
I guess we can close this as fixed in 4.7.0.


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

* [Bug c++/50431] [C++0x] bug in def array size with a lambda
  2011-09-16 11:41 [Bug c++/50431] New: lambda bug for array size def zhudiqi at 163 dot com
                   ` (4 preceding siblings ...)
  2011-11-05 21:33 ` paolo.carlini at oracle dot com
@ 2011-11-13 13:09 ` zhudiqi at 163 dot com
  5 siblings, 0 replies; 7+ messages in thread
From: zhudiqi at 163 dot com @ 2011-11-13 13:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from zhudiqi at 163 dot com 2011-11-13 12:59:47 UTC ---
(In reply to comment #5)
> I guess we can close this as fixed in 4.7.0.

Yes, I think so.


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

end of thread, other threads:[~2011-11-13 13:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-16 11:41 [Bug c++/50431] New: lambda bug for array size def zhudiqi at 163 dot com
2011-09-16 11:51 ` [Bug c++/50431] " zhudiqi at 163 dot com
2011-09-16 12:05 ` zhudiqi at 163 dot com
2011-09-16 12:45 ` [Bug c++/50431] [C++0x] bug in def array size with a lambda redi at gcc dot gnu.org
2011-09-16 14:01 ` redi at gcc dot gnu.org
2011-11-05 21:33 ` paolo.carlini at oracle dot com
2011-11-13 13:09 ` zhudiqi at 163 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).