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

如何在GCC 4.4及以上版本中忽略未知警告选项?

GCC版本兼容:抑制未识别选项导致的错误

据称,该行为在足够老旧的GCC版本中是默认行为。遗憾的是,gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0版本(另有评论称gcc 7.3.0已出现该问题)出现了退化——默认会发出警告,而-Werror选项会将其升级为错误。

我有一个程序,在新版GCC中编译正常,在GCC 11中移除-Wbidi-chars=any选项后也能正常编译。但启用该选项时,GCC 11会报错:

c++: error: unrecognized command-line option ‘-Wbidi-chars=any’

如何抑制这个被升级为错误的特定警告?既然该功能曾作为默认行为存在,想必GCC并未彻底移除它。

(次要目标:我还希望添加一些当前可用GCC版本尚不支持的警告选项以做前瞻性适配,例如升级为-Wbidi-chars=any,ucn,让旧版GCC仅识别其支持的-Wbidi-chars=any。不过这只是次要目标,我已将这些选项记录在清单中,待项目主GCC版本升级时再处理。核心诉求是避免为仍在使用的旧版GCC做出妥协,比如在CMakeLists.txt中添加编译器版本条件判断。)

我的完整编译选项如下:

add_compile_options(
    -finput-charset=UTF-8 # TODO replace with CMAKE built-in!
#  enabled warnings
    -Wall
    -Walloc-zero
    -Walloca
    -Warith-conversion
    -Warray-bounds=2
    -Wattribute-alias=2
    -Wbidi-chars=any
    -Wcast-align
    -Wcast-qual
    -Wconversion
    -Wdate-time
    -Wdisabled-optimization
    -Wdouble-promotion
    -Wduplicated-branches
    -Wduplicated-cond
    -Werror
    -Wextra
    -Wfloat-conversion
    -Wfloat-equal
    -Wformat-overflow=2
    -Wformat-signedness
    -Wformat-truncation=2
    -Wformat-y2k
    -Winline
    -Winvalid-pch
    -Wlogical-op
    -Wmissing-include-dirs
    -Wnormalized=nfkc
    -Wopenmp-simd
    -Wpacked
    -Wpedantic
    -Wredundant-decls
    -Wshadow
    -Wshift-overflow=2
    -Wsign-conversion
    -Wstrict-overflow=5
    -Wstringop-overflow=4
    -Wsuggest-attribute=noreturn
    -Wsync-nand
    -Wtrampolines
    -Wundef
    -Wuninitialized
    -Wunsafe-loop-optimizations
    -Wunused-const-variable=2
    -Wunused-macros
    -Wuseless-cast
    -Wvector-operation-performance
    -Wvla
    -Wzero-as-null-pointer-constant
# disabled warnings
    -Wno-parentheses
)

内容的提问来源于stack exchange,提问作者Zsar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.02 03:13:10