小编Chi*_*its的帖子

如何让 clang 发出关于非常简单的缩小的警告

如果我使用 clang 工具,建议使用 clang 或 clang 工具链的某些部分来告诉我,例如将 an 传递int给需要 a 的函数short可能是一个坏主意?
鉴于这个非常简单的程序

static short sus = 0;
void foo(short us) {
  sus = us;
}

int main() {
  int i = 500000;
  foo(i);   // any indication from clang this might be a bad idea
  return 0;
}
Run Code Online (Sandbox Code Playgroud)
  • 我尝试过 -Wall 和 -Wextra,
  • 我尝试过使用 cppcoreguidelines-narrowing-conversions 进行 clang-tidy
  • 我尝试过 clang -analyze

我一定错过了一些非常简单的东西,对吧?

c++ compiler-warnings narrowing clang++

6
推荐指数
1
解决办法
696
查看次数

标签 统计

c++ ×1

clang++ ×1

compiler-warnings ×1

narrowing ×1