------- Additional Comments From lars at trolltech dot com 2005-04-08 16:35 ------- Subject: Re: [4.0 Regression] anonymous types and templates and rejecting valid code
On Friday 08 April 2005 17:34, mark at codesourcery dot com wrote: > ------- Additional Comments From mark at codesourcery dot com 2005-04-08 > 15:34 ------- Subject: Re: [4.0 Regression] anonymous types and templates > and rejecting valid code > > lars at trolltech dot com wrote: > > ------- Additional Comments From lars at trolltech dot com 2005-04-08 > > 14:36 ------- Hi Mark, > > > > (In reply to comment #3) > > > >>This code is invalid. The use of ">>" requires the instantiation of the > >>declaration of the overloaded "operator>>", but that instantiation fails > > > > because > > > >>one of the template argument is anonymous. > > > > I don't see why the code is invalid. If you leave out the forward > > declaration of the template operator everything compiles fine, as the > > values in the anonymous enum get cast to integers, and the builtin > > operator>>(int, int) applies. > > Lars -- > > As I said earlier in the thread, there is now an open DR about this > issue. So, it might be resolved either way, eventually. Sorry, I didn't see the connection clearly. I was just wondering as we got a few bug reports about compile failures using Qt with gcc 4. > But, what the standard says at present is that you do overload > resolution on both operators. That requires that you instantiate their > declarations, and the instantiation of the one using anonymous enums is > invalid. There's nothing in the standard that says that you discard > instantiations that don't work -- except in cases of SFINAE. And SFINAE > does not let you ignore all errors, as some people think; it's a very > specific set. I haven't read the standard to that level I have to admit :) But if this invalid instantiation can't be ignored it seems to mean to me that one can not use any anonymous enum in C++ (better in a C++ header), as you would get compile errors as soon as someone uses a template to overload an operator that happens to be used together with values in the enum. Cheers, Lars -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19404