public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109340] New: Inconsistent diagnostics for invalid member types in union
@ 2023-03-29 20:55 redi at gcc dot gnu.org
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
0 siblings, 2 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-29 20:55 UTC (permalink / raw)
To: gcc-bugs
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-29 23:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 20:55 [Bug c++/109340] New: Inconsistent diagnostics for invalid member types in union redi at gcc dot gnu.org
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
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).