没有锵在结构未初始化的警告场 [英] No Clang warning for uninitialized field in struct

查看:132
本文介绍了没有锵在结构未初始化的警告场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下结构:

typedef struct foo {
    int a;
    int b;
} foo;

我的编译器的问题为下面的语句没有警告:

My compiler issues no warning for the following statement:

foo m = {300}

为什么没有发出警告?我期望的警告,因为我还没有对结构的决赛场上提供的任何值。

Why is no warning emitted? I expected a warning, since I have not provided any value for the final field of the struct.

下面是我的编译器调用:

Here is my compiler invocation:

gcc -Wall -Wpadded -Wuninitialized -g bar.c

下面是我的gcc版本:

Here is my gcc version:

Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

请问flipped_move场只包含垃圾?这安全吗?

Will the flipped_move field just contain garbage? Is this safe?

推荐答案

-Wmissing场初始化值会警告你在你的结构初始化缺少字段初始化。

-Wmissing-field-initializers will warn you about missing field initializers in your struct initialization.

然而,它看起来像铿锵该标志的不会警告你,如果你选择初始化结构没有值。
例如:

However, it looks like on clang that flag won't warn you if you choose to initialize a struct with no values. For example

struct foo{
  int a;
};

int main(int argc, char **argv) {
  struct foo f = {};
  return 0;
}

将发出任何警告,即使 -Wmissing场初始化值上。如果您想在这种情况下,警告以及您应该添加 -Wgnu空初始值设定

Will emit no warnings even with -Wmissing-field-initializers on. If you'd like warnings in this case as well you should add the -Wgnu-empty-initializer.

虽然你问铛,这也适用于GCC

当你在 -Wmissing场初始化值通过GCC将发出警告,这两种情况。没有 -Wgnu空初始值设定标志GCC。

Although you asked about clang, this also works in GCC
GCC will emit warnings for both cases when you pass in -Wmissing-field-initializers. There is no -Wgnu-empty-initializer flag for GCC.

这篇关于没有锵在结构未初始化的警告场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆