我正在使用-Wlto-type-mismatch和-Werror设置gcc编译(为了项目的其余部分).我有extern struct一个灵活的阵列,引发lto-type-mismatch警告/错误.
这是从一个例子中提取的代码:
HH:
typedef struct {
int i;
int ints[];
} struct_t;
Run Code Online (Sandbox Code Playgroud)
AC:
#include "h.h"
extern struct_t my_struct;
int main() { // just here to avoid optimizing away the decls
return my_struct.ints[0];
}
Run Code Online (Sandbox Code Playgroud)
公元前:
#include "h.h"
struct_t my_struct = {
20,
{
1,
2,
},
};
Run Code Online (Sandbox Code Playgroud)
编译(在这里使用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
Run Code Online (Sandbox Code Playgroud)
我试过包装一个或两个声明
#pragma gcc diagnostic push
#pragma gcc diagnostic ignore "-Wlto-type-mismatch"
<decl>
#pragma gcc diagnostic pop
Run Code Online (Sandbox Code Playgroud)
但是我无法抑制警告,可能是因为它是一个链接时优化,并且#pragma线路在那时已经很久了.
题
你能建议一些方法来编译并在其他地方保留警告吗?(或者-Wlto-type-mismatch不应该抱怨灵活的阵列?如果是这样,我可以提交错误报告.)
在询问 gcc-help 邮件列表后,我提交了一个错误:https://gcc.gnu.org/bugzilla/show_bug.cgi?id =81440 。有事会在这里跟进。]
后续:从 gcc 7.3.1 或更早版本开始,该错误已得到修复。
| 归档时间: |
|
| 查看次数: |
850 次 |
| 最近记录: |