7

我正在做一个 gcc 编译-Wlto-type-mismatch-Werror设置(为了项目的其余部分)。我有extern struct一个灵活的数组,它会引发lto-type-mismatch警告/错误。

以下是将代码简化为示例:

呵呵:

typedef struct {
  int i;
  int ints[];
} struct_t;

交流:

#include "h.h"

extern struct_t my_struct;

int main() {  // just here to avoid optimizing away the decls
  return my_struct.ints[0];
}

公元前:

#include "h.h"

struct_t my_struct = {
  20,
  {
    1,
    2,
  },
};

编译(此处使用 arm gcc,但使用本机 gcc 也会失败)

$ arm-none-eabi-gcc -flto -Wlto-type-mismatch -Werror a.c b.c -o foo
a.c:3:17: error: size of 'my_struct' differ from the size of original declaration [-Werror=lto-type-mismatch]
 extern struct_t my_struct;
                 ^
b.c:3:10: note: 'my_struct' was previously declared here
 struct_t my_struct = {
          ^
lto1: all warnings being treated as errors

我尝试将一个或两个声明包装在

#pragma gcc diagnostic push
#pragma gcc diagnostic ignore "-Wlto-type-mismatch"
<decl>
#pragma gcc diagnostic pop

但我无法抑制警告,可能是因为它是链接时优化,并且此时#pragma线路早已消失。

问题

你能建议一些方法来编译它并在其他地方保留警告吗?(或者-Wlto-type-mismatch不应该抱怨灵活数组?如果是这样,我可以提交错误报告。)

4

1 回答 1

2

在查询 gcc-help 邮件列表后,我提交了一个错误:https ://gcc.gnu.org/bugzilla/show_bug.cgi?id=81440 。有事会在这里跟进。]

跟进:该错误已在 gcc 7.3.1 或更早版本中修复。

于 2017-07-14T04:10:40.850 回答