作者:Y_虞儿 | 来源:互联网 | 2023-01-29 19:45
我正在使用-Wlto-type-mismatch
和-Werror
设置gcc编译(为了项目的其余部分).我有extern
struct
一个灵活的阵列,引发lto-type-mismatch
警告/错误.
这是从一个例子中提取的代码:
HH:
typedef struct {
int i;
int ints[];
} struct_t;
AC:
#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"
#pragma gcc diagnostic pop
但是我无法抑制警告,可能是因为它是一个链接时优化,并且#pragma
线路在那时已经很久了.
题
你能建议一些方法来编译并在其他地方保留警告吗?(或者-Wlto-type-mismatch
不应该抱怨灵活的阵列?如果是这样,我可以提交错误报告.)