golang/go · error

unfinished escaping

Error message

unfinished escaping

What it means

Thrown by splitQuoted (src/cmd/cgo/gcc.go) when the input string ends while still in escape mode — i.e. the final character was a backslash with nothing following it. The `escaped` flag stays true at end-of-string.

Source

Thrown at src/cmd/cgo/gcc.go:182

			continue
		case unicode.IsSpace(r):
			if quoted || i > 0 {
				quoted = false
				args = append(args, string(arg[:i]))
				i = 0
			}
			continue
		}
		arg[i] = r
		i++
	}
	if quoted || i > 0 {
		args = append(args, string(arg[:i]))
	}
	if quote != 0 {
		err = errors.New("unclosed quote")
	} else if escaped {
		err = errors.New("unfinished escaping")
	}
	return args, err
}

// loadDebug runs gcc to load debug information for the File. The debug
// information will be saved to the debugs field of the file, and be
// processed when Translate is called on the file later.
// loadDebug is called concurrently with different files.
func (f *File) loadDebug(p *Package) {
	for _, cref := range f.Ref {
		// Convert C.ulong to C.unsigned long, etc.
		cref.Name.C = cname(cref.Name.Go)
	}

	ft := fileTypedefs{typedefs: make(map[string]bool)}
	numTypedefs := -1
	for len(ft.typedefs) > numTypedefs {
		numTypedefs = len(ft.typedefs)

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Remove or double the trailing backslash in the $CC / $GCC value.
  2. If a literal backslash is required at the end, escape it as '\\'.
  3. Re-export CC without the trailing backslash and rebuild.
  4. Echo the variable with `printf '%s\n' "$CC" | cat -A` to reveal hidden trailing characters.

Example fix

// before
export CC='gcc -DFOO=bar\'
// after
export CC='gcc -DFOO=bar\\'
Defensive patterns

Strategy: validation

Validate before calling

// Reject a CC/GCC value ending in an unescaped backslash.
func endsClean(s string) bool {
    if s == "" { return true }
    backslashes := 0
    for i := len(s)-1; i >= 0 && s[i] == '\\'; i-- { backslashes++ }
    return backslashes%2 == 0
}

Prevention

When it happens

Trigger: splitQuoted receives a value whose last character is '\'. For cgo this is again the $CC/$GCC variable or a flag string. Example: CC='gcc -DFOO=bar\' leaves the parser expecting an escaped character that never arrives.

Common situations: A trailing backslash in CC/GCC from a line-continuation that got collapsed incorrectly; copy-paste artifacts; Makefile $(...) expansions that produce a dangling backslash; shell-quoting mistakes where '\' was meant literally but appears at the end.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/5396785c0426ccf9. Report an issue: GitHub.