https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66431

            Bug ID: 66431
           Summary: [go] Unexpected function return value after it is
                    redefined in closure
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: lomov.as at gmail dot com
                CC: cmang at google dot com
  Target Milestone: ---

I'm not sure about where is bug: in gccgo or in go. I couldn't find this case
in go specs and I decided to write here.

This code has different behaviour in golang (tested on 1.3.1-1.4.2) and gccgo
(5.1.0):
```
package main

import "fmt"

func testFunction() (value int, err error) {
    value = 1
    fmt.Println("In the beginning value is : ", value)
    closure := func() (error) {
        value = 2
        fmt.Println("value is changed in closure : ", value)
        return nil
    }
    return value, closure()
}

func main() {
    result, err := testFunction()
    fmt.Println("final result is : ", result)
    fmt.Println("err is : ", err)
}
```

Go lang 1.4.2 returns following result:
```
In the beginning value is :  1
value is changed in closure :  2
final result is :  2
err is :  <nil>
```

And GCC Go prints following:
```
In the beginning value is :  1
value is changed in closure :  2
final result is :  1
err is :  <nil>
```

The thing is that in GCC Go a value is returned unchanged by closure.

I use following flags to configure gcc 5.1.0 go before build:
```
../src/configure --enable-threads=posix --enable-shared --enable-__cxa_atexit \
    --enable-languages=c,c++,go --enable-secureplt --enable-checking=yes
--with-long-double-128 \
    --enable-decimal-float --disable-bootstrap --disable-alsa
--disable-multilib \
    --prefix=/usr/local/gccgo
```

I run Linux on power architecture:
```
uname -a
Linux jumpbox 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:15:29 UTC 2015
ppc64le ppc64le ppc64le GNU/Linux
```

Reply via email to