Summary: | [4.0 Regression] anonymous types and templates and rejecting valid code | ||
---|---|---|---|
Product: | gcc | Reporter: | André Wöbbeking <Woebbeking> |
Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | normal | CC: | amu, dominik.strasser, gcc-bugs, lars, mmitchel, pinskia |
Priority: | P2 | Keywords: | rejects-valid |
Version: | 4.0.0 | ||
Target Milestone: | 4.0.0 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2005-01-12 18:53:44 |
Description
André Wöbbeking
2005-01-12 18:46:14 UTC
Confirmed, reduced testcase: class Base; template<typename Type> inline Base const& operator>>(Base const& rConfiguration, Type& rType) ; enum { HSize = 6, HMask = 0x3f, VMask = HMask << HSize }; int verData(unsigned int data){ return (int)( (data & VMask) >> HSize ); } Note it start failing after "2004-12-11". This is valid code we should reject the template as it does not fit with the arguments. The only patch which makes sense (as it is not really that bogus really as shown in this example): PR c++/17413 * pt.c (check_instantiated_args): Remove bogus SFINAE code. 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. 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. So this compiles just fine (and to the correct code as far as I can tell): enum { HSize = 6, HMask = 0x3f, VMask = HMask << HSize }; int verData(unsigned int data){ return (int)( (data & VMask) >> HSize ); } while this doesn't: class Base; template<typename Type> inline Base const& operator>>(Base const& rConfiguration, Type& rType) ; enum { HSize = 6, HMask = 0x3f, VMask = HMask << HSize }; int verData(unsigned int data){ return (int)( (data & VMask) >> HSize ); } The types in the forward declaration have no connection whatsoever with the values in the anonymous union, so the template should not apply. Lars 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.
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.
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 *** Bug 21244 has been marked as a duplicate of this bug. *** |