I'm doing a gcc compile with -Wlto-type-mismatch
and -Werror
set (for the good of the rest of the project). I have an extern
struct
with a flexible array that is provoking an lto-type-mismatch
warning/error.
Here's the code distilled down to an example:
h.h:
typedef struct {
int i;
int ints[];
} struct_t;
a.c:
#include "h.h"
extern struct_t my_struct;
int main() { // just here to avoid optimizing away the decls
return my_struct.ints[0];
}
b.c:
#include "h.h"
struct_t my_struct = {
20,
{
1,
2,
},
};
Compiling (using arm gcc here, but it also fails with native 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
I've tried wrapping one or both of the declarations in
#pragma gcc diagnostic push
#pragma gcc diagnostic ignore "-Wlto-type-mismatch"
<decl>
#pragma gcc diagnostic pop
but I can't suppress the warning, possibly because it is a link-time optimization and the #pragma
lines are long gone at that point.
Question
Can you suggest some way to get this to compile and still preserve the warning elsewhere? (Or should -Wlto-type-mismatch
not be complaining about the flexible array? If so, I can submit a bug report.)
After inquiring on gcc-help mailing list, I submitted a bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81440. Will follow up here when something happens.]
Followup: the bug has been fixed as of gcc 7.3.1 or earlier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With