From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F1E1B3858436; Wed, 29 Mar 2023 20:55:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1E1B3858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680123305; bh=ZcpK9CTFlrPlTTMLb9AMLmyftYQobwwhjrYylU9v6rQ=; h=From:To:Subject:Date:From; b=Q6AmLaCofYKeAO9SOEDkdamI7hog7u33DSVuE1N3kGdw9/F5y5VkRpKO1y+Ebn2IV U53MkpXlLf1EZQjnizfTAp3JkllE5VyJi49vtVcJmr02P2Zsb8UOvMwg+6NSTjYpWs nhNEjjL9BWeE/YN1AbxCeR1ffza1E1ViubtJL0kE= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109340] New: Inconsistent diagnostics for invalid member types in union Date: Wed, 29 Mar 2023 20:55:05 +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.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org 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 keywords 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=3D109340 Bug ID: 109340 Summary: Inconsistent diagnostics for invalid member types in union Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- template union U { U(); T t; }; U ref; U arr; U func; G++ correctly rejects this, but has three very different errors for basical= ly the same problem: union.cc: In instantiation of =E2=80=98union U=E2=80=99: union.cc:9:9: required from here union.cc:6:5: error: non-static data member =E2=80=98U::t=E2=80=99 in= a union may not have reference type =E2=80=98int&=E2=80=99 6 | T t; | ^ union.cc: In instantiation of =E2=80=98union U=E2=80=99: union.cc:10:10: required from here union.cc:6:5: error: flexible array member =E2=80=98U::t=E2=80=99 in uni= on union.cc: In instantiation of =E2=80=98union U=E2=80=99: union.cc:11:10: required from here union.cc:6:5: error: data member =E2=80=98U::t=E2=80=99 invalidly de= clared function type Specifically: error: non-static data member =E2=80=98U::t=E2=80=99 in a union may n= ot have reference type =E2=80=98int&=E2=80=99 error: flexible array member =E2=80=98U::t=E2=80=99 in union error: data member =E2=80=98U::t=E2=80=99 invalidly declared functio= n type Could we use the same phrasing for all three? The first one seems the best, and the third one seems the worst. For comparison, Clang says: union.cc:6:5: error: union member 't' has reference type 'int &' T t; ^ union.cc:9:9: note: in instantiation of template class 'U' requested here U ref; ^ union.cc:6:5: error: data member instantiated with function type 'int ()' T t; ^ union.cc:11:10: note: in instantiation of template class 'U' reques= ted here U func; ^ 2 errors generated. Not very good either. EDG says: "union.cc", line 6: error: incomplete type is not allowed T t; ^ detected during instantiation of union "U [with T=3Dint []]" a= t line 10 "union.cc", line 6: error: a function type is not allowed here T t; ^ detected during instantiation of union "U [with T=3Dint ()]" a= t line 11 2 errors detected in the compilation of "union.cc".=