From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EF2023858C60; Wed, 29 Nov 2023 10:49:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF2023858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701254973; bh=0q7QpzQzoFynYRXab3xT5wgxsFaN8nTbFlHtV7neT70=; h=From:To:Subject:Date:From; b=jm9G7GdxGUKYPZ/mpsi7sldT/vEd1bezFZpaBKDFynAIqWMoO4uGppHPuC0vwJdLb GrbENbCGaFB9LA9k91wd4eFrhO9t2PF4XN34IJu8v1S1Wep/DYBcNiUmo+9tV081RP IhCAweno2hOGTIZJM1ClDBeoml2obpjiPmJ/fO2I= From: "ville.syrjala at linux dot intel.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/112761] New: Using incomplete array types in function prototypes doesn't work Date: Wed, 29 Nov 2023 10:49:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ville.syrjala at linux dot intel.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112761 Bug ID: 112761 Summary: Using incomplete array types in function prototypes doesn't work Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ville.syrjala at linux dot intel.com Target Milestone: --- struct foo; void func(struct foo bar[]); int main(void) { } error: array type has incomplete element type =E2=80=98struct foo=E2=80=99 3 | void func(struct foo bar[]); | ^~~ This prevents using the array syntax in function prototypes with opaque typ= es. So I have to give up either: - the array syntax, which means there is no longer any hint to the reader whether the function takes an array or a pointer to a single object - or the opaque type which is even worse since the clean abstraction is rui= ned (not to mention the resulting stable ABI issues). I couldn't immediately find anything in the spec that says this is illegal: - "6.7.6.2 Array declarators ... If the size is not present, the array type is an incomplete type." - "6.7.6.3 Function declarators ... If the function declarator is not part of a definition of that function, parameters may have incomplete type and may use the [*] notation in their sequences of declarator specifiers to specify variable length array types." But maybe I just don't know how to read the spec correctly? Side note: This also affects the (arguably hideous) "ptr[static 1]" syntax which would= be beneficial to indicate that you can't pass in a null pointer. But I suppose that one is explicitly forbidden by the spec since we do specify a size for= the "array" and thus it is not allowed to be an incomplete type.=