]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: fix unexpected semicolon in rewritten line
authorRuss Cox <rsc@golang.org>
Tue, 30 Apr 2019 18:56:12 +0000 (14:56 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 7 May 2019 12:48:04 +0000 (12:48 +0000)
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: Ian Lance Taylor <iant@golang.org>
misc/cgo/test/issue29781.go
src/cmd/cgo/godefs.go

index 0fd8c08b8eb0e41850018005e8deeb813406b4a5..c80919dc17250a7df5dd6c1507de659bb1438125 100644 (file)
@@ -11,7 +11,18 @@ package cgotest
 // #define ISSUE29781C 0
 import "C"
 
+var issue29781X struct{ X int }
+
+func issue29781F(...int) int { return 0 }
+
 func issue29781G() {
        var p *C.char
        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))
 }
index 64384a606b261f03874bb6e48b1bd5fe898c9690..b4fd9c5a6e326661b0383d77f80319b0a6bebac6 100644 (file)
@@ -136,21 +136,31 @@ func gofmt(n interface{}) string {
 // (due to the printer possibly inserting newlines because of position
 // information) operators.
 var gofmtLineReplacer = strings.NewReplacer(
-       "{\n", "{",
-       ",\n", ",",
+       // Want to replace \n without ; after everything from
+       // 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", "! ", // not possible in gofmt today
+       "(\n", "(",
+       "[\n", "[", // not possible in gofmt today
+       "{\n", "{",
+       ",\n", ",",
+       ".\n", ". ",
+       ":\n", ": ", // not possible in gofmt today
+
        "\n", ";",
 )