clang没有检测到开关坠落

时间:2018-02-25 18:59:11

标签: c clang fall-through

我希望clang能够抓住我无意中的“切换”声明。这个shell脚本演示了我的失败;我在脚本本身之后显示输出。我做错了什么?

#!/bin/sh

cat <<EOD > 1.c
#include <stdio.h>
int main(void)
{
  int etwas=5;
  switch(etwas)
  {
    case 5:
    {
      printf("It's 5.\n");
    }
    case 6:
    {
      printf("It's 6.\n");
    }
    default:
    {
      printf("It's something else\n");
      break;
    }
  }
  return 0;
}
EOD

rm -f 1
clang --version
echo === demonstrating that unrecognized warning names are not allowed ===
clang -Wnonsense-warning -Werror -Wall 1.c -o 1
echo === The real compile follows. ===
clang -Wimplicit-fallthrough 1.c -o 1
echo === The execution follows. ===
./1

输出:

FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on LLVM 4.0.0)
Target: x86_64-unknown-freebsd11.1
Thread model: posix
InstalledDir: /usr/bin
=== demonstrating that unrecognized warning names are not allowed ===
error: unknown warning option '-Wnonsense-warning'
      [-Werror,-Wunknown-warning-option]
=== The real compile follows. ===
=== The execution follows. ===
It's 5.
It's 6.
It's something else

0 个答案:

没有答案