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".