public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* -Wlto-type-mismatch during lto with flexible array members in mixed C & C++ codebase
@ 2022-01-12  8:57 Hans-Joerg Schurr
  0 siblings, 0 replies; only message in thread
From: Hans-Joerg Schurr @ 2022-01-12  8:57 UTC (permalink / raw)
  To: gcc-help

I'm in the process of adding some C++ code to a C codebase. This codebase uses
flexible array members in structs.  In my understanding GCC supports this as a
compiler extension.  If I compile my code with lto I get a -Wlto-type-mismatch 
warning.

I added a minimal example to the end of this mail.

If I compile the example with
> gcc -c -flto a_struct.c
> g++ -c -flto b_struct.cc
> g++ -Wlto-type-mismatch a_struct.o b_struct.o
the last command prints 
> a_struct.c:3:17: warning: type of ‘my_struct’ does not match original
declaration [-Wlto-type-mismatch]
> [...]

The example is taken from this bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81440
where GCC erroneously produced this warning for pure C code.

Nevertheless, I suspect that in my case the reason for this warning is some
error on my side on mixing C and C++.
I would be happy if you have any insight into this.

(I'm using gcc version 10.3.0)

// ab_struct.h 
typedef struct {
    int i;
    int ints[];
} struct_t;

// a_struct.c

#include "ab_struct.h"

extern struct_t my_struct;

int main() {
   return my_struct.ints[0];
}

// b_struct.cc

#include "ab_struct.h"

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-12  8:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12  8:57 -Wlto-type-mismatch during lto with flexible array members in mixed C & C++ codebase Hans-Joerg Schurr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).