Commit a88cb1d8 authored by Russ Cox's avatar Russ Cox

cmd/cgo: fix unexpected semicolon in rewritten line

Followup to CL 157961 and CL 158457.
Finish the list of operators and punctuation
that disable semicolon insertion at end-of-line
The reported case was "(" but "." was also missing.

Fixes #31017.

Change-Id: I0c06443f38dc8250c62e3aadd104abfa0e3be074
Reviewed-on: https://go-review.googlesource.com/c/go/+/174524
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 3e7e2546
...@@ -11,7 +11,18 @@ package cgotest ...@@ -11,7 +11,18 @@ package cgotest
// #define ISSUE29781C 0 // #define ISSUE29781C 0
import "C" import "C"
var issue29781X struct{ X int }
func issue29781F(...int) int { return 0 }
func issue29781G() { func issue29781G() {
var p *C.char var p *C.char
C.issue29781F(&p, C.ISSUE29781C+1) C.issue29781F(&p, C.ISSUE29781C+1)
C.issue29781F(nil, (C.int)(
0))
C.issue29781F(&p, (C.int)(0))
C.issue29781F(&p, (C.int)(
0))
C.issue29781F(&p, (C.int)(issue29781X.
X))
} }
...@@ -136,21 +136,31 @@ func gofmt(n interface{}) string { ...@@ -136,21 +136,31 @@ func gofmt(n interface{}) string {
// (due to the printer possibly inserting newlines because of position // (due to the printer possibly inserting newlines because of position
// information) operators. // information) operators.
var gofmtLineReplacer = strings.NewReplacer( var gofmtLineReplacer = strings.NewReplacer(
"{\n", "{", // Want to replace \n without ; after everything from
",\n", ",", // https://golang.org/ref/spec#Operators_and_punctuation
// EXCEPT ++ -- ) ] }
"++\n", "++;", "++\n", "++;",
"--\n", "--;", "--\n", "--;",
"+\n", "+",
"-\n", "-", "+\n", "+ ",
"*\n", "*", "-\n", "- ",
"/\n", "/", "*\n", "* ",
"%\n", "%", "/\n", "/ ",
"&\n", "&", "%\n", "% ",
"|\n", "|", "&\n", "& ",
"^\n", "^", "|\n", "| ",
"<\n", "<", "^\n", "^ ",
">\n", ">", "<\n", "< ",
"=\n", "=", ">\n", "> ",
"=\n", "= ",
"!\n", "! ", // not possible in gofmt today
"(\n", "(",
"[\n", "[", // not possible in gofmt today
"{\n", "{",
",\n", ",",
".\n", ". ",
":\n", ": ", // not possible in gofmt today
"\n", ";", "\n", ";",
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment