From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.4-mail.net (mail.4-mail.net [49.12.225.80]) by sourceware.org (Postfix) with ESMTPS id 343123858416 for ; Wed, 12 Jan 2022 08:57:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 343123858416 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=schurr.at Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=schurr.at Received: from [192.168.43.4] (unknown [51.15.126.113]) (Authenticated sender: hans-joerg@schurr.at) by mail.4-mail.net (Postfix) with ESMTPSA id C4A7F16F348 for ; Wed, 12 Jan 2022 09:57:55 +0100 (CET) Message-ID: <6d49977ba5b89f201f5a0cb1e7c82c75a3c8cdaa.camel@schurr.at> Subject: -Wlto-type-mismatch during lto with flexible array members in mixed C & C++ codebase From: Hans-Joerg Schurr To: gcc-help@gcc.gnu.org Date: Wed, 12 Jan 2022 09:57:54 +0100 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: mail.4-mail.net; auth=pass smtp.auth=hans-joerg@schurr.at smtp.mailfrom=lists@schurr.at X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Jan 2022 08:57:58 -0000 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 } };