-Wlto-type-mismatch during lto with flexible array members in mixed C & C++ codebase

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 }
};



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux