You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Go 1.18搭配gcc-14时泛型语法无法正常使用的问题求助

Go 1.18搭配gcc-14时泛型语法无法正常使用的问题求助

几个月前我安装了gcc14,同时也配置了Go环境。现在尝试用Go写泛型代码的时候遇到了麻烦——编译器完全不识别泛型语法,比如我写了这段泛型函数:

func SlicesIndex[S ~[]E, E comparable](s S, v E) int {    
    for i := range s {        
        if v == s[i] {            
            return i        
        }    
    }    
    return -1 
}

结果编译器抛出了这样的错误:

./main.go:12:17: error: expected ‘(’                
12 | func SlicesIndex[S ~[]E, E comparable](s S, v E) int {

有没有大佬能帮忙分析下这是哪里出问题了呀?

备注:内容来源于stack exchange,提问作者FERcsI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 16:28:16