public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-109340-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109340 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<typename T> union U { U(); T t; }; U<int&> ref; U<int[]> arr; U<int()> func; G++ correctly rejects this, but has three very different errors for basically the same problem: union.cc: In instantiation of ‘union U<int&>’: union.cc:9:9: required from here union.cc:6:5: error: non-static data member ‘U<int&>::t’ in a union may not have reference type ‘int&’ 6 | T t; | ^ union.cc: In instantiation of ‘union U<int []>’: union.cc:10:10: required from here union.cc:6:5: error: flexible array member ‘U<T>::t’ in union union.cc: In instantiation of ‘union U<int()>’: union.cc:11:10: required from here union.cc:6:5: error: data member ‘U<int()>::t’ invalidly declared function type Specifically: error: non-static data member ‘U<int&>::t’ in a union may not have reference type ‘int&’ error: flexible array member ‘U<T>::t’ in union error: data member ‘U<int()>::t’ invalidly declared function 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<int &>' requested here U<int&> 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<int ()>' requested here U<int()> 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<T> [with T=int []]" at line 10 "union.cc", line 6: error: a function type is not allowed here T t; ^ detected during instantiation of union "U<T> [with T=int ()]" at line 11 2 errors detected in the compilation of "union.cc".
next reply other threads:[~2023-03-29 20:55 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-29 20:55 redi at gcc dot gnu.org [this message] 2023-03-29 23:38 ` [Bug c++/109340] " cvs-commit at gcc dot gnu.org 2023-03-29 23:41 ` redi at gcc dot gnu.org
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=bug-109340-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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: linkBe 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).