public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hans-Joerg Schurr <lists@schurr.at>
To: gcc-help@gcc.gnu.org
Subject: -Wlto-type-mismatch during lto with flexible array members in mixed C & C++ codebase
Date: Wed, 12 Jan 2022 09:57:54 +0100	[thread overview]
Message-ID: <6d49977ba5b89f201f5a0cb1e7c82c75a3c8cdaa.camel@schurr.at> (raw)

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

                 reply	other threads:[~2022-01-12  8:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d49977ba5b89f201f5a0cb1e7c82c75a3c8cdaa.camel@schurr.at \
    --to=lists@schurr.at \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).