The C++0x lambda branch

2009-04-27 Thread Esben Mose Hansen
Hi,

I have very much been looking forward to the including of the lambda part of 
C++0x. I have been playing around with the lambda branch of gcc, which at 
least superficially works well apart from assorted bugs. 

What can I do to make lambdas part of a future release of gcc?

Where do I report/track bugs to the lambda branch?

Or should I contact the maintainer directly? 

-- 
Kind regards, Esben


Re: gcc-in-cxx update / multi-targeted gcc

2009-04-29 Thread Esben Mose Hansen
On Wednesday 29 April 2009 12:47:04 Joern Rennecke wrote:
> Something which I miss in C++ is a way to declare that a function uses
> an integral type to pass an enum value (in arguments or return value),
> and then at function definition time only check that the integral type
> is sufficently large to hold the enum, and then for type checking purposes
> treat the parameter / return value as if it had been declared as this enum.

This is exactly N2764, which should be part of C++0x --- at least it seems to 
be in the draft around p.149. But not part of gcc 4.4. unfortunately.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf
http://gcc.gnu.org/projects/cxx0x.html

-- 
Kind regards, Esben


[lambda] Segmentation fault in simple lambda program

2009-04-29 Thread Esben Mose Hansen
Hi,

this program SEGFAULTs

#include 

int main() {
  int numbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  const std::size_t nn = sizeof(numbers)/sizeof(int);
  int sum = 0;
  int f = 5;
  std::for_each(&numbers[0], &numbers[nn],  [&]  (int n)  { 
sum += n * f; 
  });

}

Now, my assembly days are some 15 years past, but the disassembly is

0x08048424 <_ZZ4mainENK9__lambda0clEiz+0>:  push   %ebp
0x08048425 <_ZZ4mainENK9__lambda0clEiz+1>:  mov%esp,%ebp
0x08048427 <_ZZ4mainENK9__lambda0clEiz+3>:  mov0x8(%ebp),%eax
0x0804842a <_ZZ4mainENK9__lambda0clEiz+6>:  mov0x4(%eax),%eax
0x0804842d <_ZZ4mainENK9__lambda0clEiz+9>:  mov0x8(%ebp),%edx
0x08048430 <_ZZ4mainENK9__lambda0clEiz+12>: mov0x4(%edx),%edx
0x08048433 <_ZZ4mainENK9__lambda0clEiz+15>: mov(%edx),%ecx
0x08048435 <_ZZ4mainENK9__lambda0clEiz+17>: mov0x8(%ebp),%edx
0x08048438 <_ZZ4mainENK9__lambda0clEiz+20>: mov(%edx),%edx
0x0804843a <_ZZ4mainENK9__lambda0clEiz+22>: mov(%edx),%edx
0x0804843c <_ZZ4mainENK9__lambda0clEiz+24>: imul   0xc(%ebp),%edx
0x08048440 <_ZZ4mainENK9__lambda0clEiz+28>: lea(%ecx,%edx,1),%edx
=> SEGFAULT 0x08048443 <_ZZ4mainENK9__lambda0clEiz+31>: mov%edx,(%eax)
0x08048445 <_ZZ4mainENK9__lambda0clEiz+33>: pop%ebp
0x08048446 <_ZZ4mainENK9__lambda0clEiz+34>: ret

I have marked the segfault spot. I also find 0x0804843a suspicious, but then I 
don't even know how to print register values in gcc. 

Any pointers to where I should dig? I am completely new to gcc hacking, just 
dying to get lambda into gcc 4.5 :)

P.S: Shouldn't gcc show the actual lambda function code ( sum+= f*c; ) instead 
of the assembly code in any case?

Thanks for your help!

-- 
Kind regards, Esben


Re: [lambda] Segmentation fault in simple lambda program

2009-04-30 Thread Esben Mose Hansen
On Thursday 30 April 2009 19:19:31 you wrote:
> When I try to specify the capture it works ((&sum, &f) works too but f is
> const):
>
> #include 
>
> int
> main(void)
> {
>   int numbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
>   const std::size_t nn = sizeof(numbers)/sizeof(int);
>   int sum = 0;
>   int f = 5;
>
>   //std::for_each(&numbers[0], &numbers[nn], [&](int n) { sum += n * f; });
>
>   std::for_each(&numbers[0], &numbers[nn], [&sum, f](int n) { sum += n * f;
> });
>
>   return 0;
> }

Yup. In fact, almost any other capture block than the [&] works :) I will try 
to look at those tree options when I get sober again.

-- 
Kind regards, Esben