跳到正文

个人记录

【记录】gcc -Wall 警告意思

phigy约 2 分钟
原文

这是 2025年11月25日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2021年12月13日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

Code::blcoks - Setting - Compiler… - Other compiler options - 输入 -Wall - OK 。

Dev-c++ - Tools - Setting - Warnings - Show most warnings (-Wall) - Yes 。

  1. no return statement in function returning non-void [-Wreturn-type]

函数没有返回,属于 UB,经典案列 NOIP T2 T3 开 O2 爆零。

  1. unused variable 'X' [-Wunused-variable]

没用到某变量,可以忽略。

  1. control reaches end of non-void function [-Wreturn-type]

函数结尾处没有返回,UB不清楚,但基本会WA。

关于结尾处定义:

C++
int phigy
{
    if(x==0)return 0;
    if(x!=0)return 0;
}

这会有警告。

C++
int phigy
{
    if(x==0)return 0;
    else return 0;
}

这不会有警告。

4. suggest parentheses around assignment used as truth value [-Wparentheses]

代码
if(res=dfs(x,flew)>0)
{
            
}

此情况警告,意思是要明确是 = 不是 == 。

代码
if((res=dfs(x,flew))>0)
{
            
}

这样解决。

  1. [Warning] suggest parentheses around '+' inside '>>' [-Wparentheses]

输入输出时的运算可能与左移右移产生歧义