Skip to content

Cannot take the address of the result of append #1338

Closed
@gopherbot

Description

@gopherbot

by yiyu.jgl:

What steps will reproduce the problem?

// Example:
package main

func main() {
    _ = &append([]int{1, 2}, 3)[:]
}

What is the expected output?

A successful compile.

What do you see instead?

prog.go:4: cannot take the address of append(slice literal, 3)[:]

Which compiler are you using (5g, 6g, 8g, gccgo)?
Which operating system are you using?
Which revision are you using?  (hg identify)

Go Playground at golang.org

Please provide any additional information below.

In my opinion, it should be possible to directly take the address of append, as in
&append(a, b), but I'm not sure the spec allows it. However, it specifically says
the address operator can be used with an slice indexing operation, so I think it should
work for &append(a, b)[:]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions