clang 使用 mingw 头文件编译时不出现部分警告 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
snylonue
V2EX    程序员

clang 使用 mingw 头文件编译时不出现部分警告

  •  
  •   snylonue 2023-10-13 21:56:07 +08:00 1730 次点击
    这是一个创建于 729 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在 vscode 中配置了 clangd 插件,发现不会提示 printf/scanf 相关的警告,于是测试了一下

    #include <stdio.h> int main() { int i; scanf("%f", &i); printf("%d", i, i ,2); return 0; } 
    clang -Wall .\warn.c .\warn.c:5:5: warning: 'scanf' is deprecated: This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations] scanf("%f", &i); ^ C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stdio.h:1275:20: note: 'scanf' has been explicitly marked deprecated here _Check_return_ _CRT_INSECURE_DEPRECATE(scanf_s) ^ C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:355:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE' #define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT( \ ^ C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:345:47: note: expanded from macro '_CRT_DEPRECATE_TEXT' #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text)) ^ .\warn.c:5:17: warning: format specifies type 'float *' but the argument has type 'int *' [-Wformat] scanf("%f", &i); ~~ ^~ %d .\warn.c:6:21: warning: data argument not used by format string [-Wformat-extra-args] printf("%d", i, i ,2); ~~~~ ^ 3 warnings generated. 
    clang -Wall --target=x86_64-w64-mingw32 .\warn.c 

    gcc 使用相同头文件会显示警告

     gcc -Wall .\warn.c .\warn.c: In function 'main': .\warn.c:5:13: warning: format '%f' expects argument of type 'float *', but argument 2 has type 'int *' [-Wformat=] 5 | scanf("%f", &i); | ~^ ~~ | | | | | int * | float * | %d .\warn.c:6:12: warning: too many arguments for format [-Wformat-extra-args] 6 | printf("%d", i, i ,2); | 

    想知道有没有办法配置 clang 显示相同警告

    7 条回复    2023-10-15 21:08:08 +08:00
    shiltian
        1
    shiltian  
       2023-10-13 22:22:58 +08:00 via iPhone   1
    去 llvm-project 开个 issue ,这个是得报的
    snylonue
        2
    snylonue  
    OP
       2023-10-13 22:58:57 +08:00
    lsry
        3
    lsry  
       2023-10-13 23:22:19 +08:00
    clang -Wall --target=x86_64-w64-mingw32 test.c
    test.c:7:17: warning: format specifies type 'float *' but the argument has type 'int *' [-Wformat]
    7 | scanf("%f", &i);
    | ~~ ^~
    | %d
    test.c:8:21: warning: data argument not used by format string [-Wformat-extra-args]
    8 | printf("%d", i, i, 2);

    clang version 17.0.1
    Target: x86_64-pc-windows-msvc
    Thread model: posix

    (built by Brecht Sanders) clang version 16.0.6
    Target: x86_64-w64-windows-gnu
    Thread model: posix
    了上面,都
    ysc3839
        4
    ysc3839  
       2023-10-13 23:22:57 +08:00 via Android
    前面两个 clang 都是同一个?怀疑是跟 clang --version 里的 target 有关,用 MSYS2 装个 clang 试试吧。
    shiltian
        5
    shiltian  
       2023-10-13 23:44:51 +08:00
    @snylonue 没有 Windows 机器不能 debug ,只能给把 labels 给加上了
    tool2d
        6
    tool2d  
       2023-10-14 03:19:26 +08:00
    试了一下,我也没报
    llvm-mingw-20220906-msvcrt-i686/bin/i686-w64-mingw32-clang++.exe

    别的平台 clang 没问题。
    snylonue
        7
    snylonue  
    OP
       2023-10-15 21:08:08 +08:00
    @ysc3839
    @lsry
    我这边用 msys2 装的 clang 也没报(不是很熟悉这些工具链,不知道有没有装对
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1141 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 17:58 PVG 01:58 LAX 10:58 JFK 13:58
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86