Summary: | [DR 488] error: '<anonymous enum>' is/uses anonymous type' | ||
---|---|---|---|
Product: | gcc | Reporter: | Caolan McNamara <caolanm> |
Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | caolanm, christian.joensson, fang, gcc-bugs, ian, jason, mmarcus, mmitchel, sethml, snoonan |
Priority: | P2 | ||
Version: | 4.0.0 | ||
Target Milestone: | 4.0.2 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2006-01-15 21:04:13 | |
Attachments: |
example
tentative patch |
Description
Caolan McNamara
2005-03-22 15:45:42 UTC
Created attachment 8433 [details]
example
I think this is invalid code. Mark I think you changed the front-end code to reject this, can you comment on validness of the code attached in this bug? Yes, this is invalid code, as the template parameters involve an anonymous type. The workaround is trivial. But I'm still confused as to what exactly causes gcc to treat unnamed enums so much differently that named ones. It would be great if I could get some clarity on this. I have a handful of cases like this in the openoffice.org code base and OOo is reluctant to take the patches to fix unless sure it's currently invalid. (In reply to comment #4) > The workaround is trivial. But I'm still confused as to what exactly causes gcc > to treat unnamed enums so much differently that named ones. It would be great if > I could get some clarity on this. I have a handful of cases like this in the > openoffice.org code base and OOo is reluctant to take the patches to fix unless > sure it's currently invalid. Because the standard treats them differently. Intuitively, C++ treats unnamed enums differently than named ones, because in templates the function/class name has to be mangled, and will contain the name of the template arguments. If the template argument doesn't have a name, then the compiler can't do its job, so the standard chose to disallow unnamed enums as template arguments. For more legalese, this is specified in section 14.3.1/2 of the standard, which says: 2 A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template- argument for a template type-parameter. [Example: ... Regards Wolfgang Sounds reasonable, but it's not the case that the compiler should just silently not consider anonymous enums as candidates for template argument matching ? That has been subject to discussion (i.e. whether the attempt to use an unnamed enum as a template argument should just silently fail as a substitution failure). However, it has been decided that this is a hard error, not only a substitution failure. I am presently not quite sure about the reasoning, and I believe that there was a DR or something still pending. Mark, do you remember the details? I think this came up in a different PR before... W. Subject: Re: error: '<anonymous enum>' is/uses anonymous type'
bangerth at dealii dot org wrote:
> ------- Additional Comments From bangerth at dealii dot org 2005-03-23 19:24 -------
> That has been subject to discussion (i.e. whether the attempt to use an
> unnamed enum as a template argument should just silently fail as a
> substitution failure). However, it has been decided that this is a hard
> error, not only a substitution failure.
>
> I am presently not quite sure about the reasoning, and I believe that there
> was a DR or something still pending. Mark, do you remember the details? I
> think this came up in a different PR before...
It's swapped out of my brain, but there was another PR, and I did raise
the issue for Steve Adamczyk, to be added to the core issue list. The
basic point is that the SFINAE rules simply do not cover this case; they
precisely describe a set of situations in which no error should be
issued, and trying to use an anonymous type as a template parameter is
not among them.
Subject: Re: error: '<anonymous enum>' is/uses anonymous type' "bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes: | Intuitively, C++ treats unnamed enums differently than named ones, because | in templates the function/class name has to be mangled, and will contain | the name of the template arguments. If the template argument doesn't have | a name, then the compiler can't do its job, so the standard chose to | disallow unnamed enums as template arguments. | I know what the standard says, but the arguments used to make that rule are bogus. Those are on my list of things to fix for C++0x. If it were only mnagling, then the compiler can concoct a unique name for manglaing purposes. -- Gaby Well, I wanted to give an "inuitive" reasoning. On the other hand, how do you propose to make up a unique name if an unnamed enum is used in two different translation units as a template argument? W. Subject: Re: error: '<anonymous enum>' is/uses anonymous type' "bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes: | Well, I wanted to give an "inuitive" reasoning. I understood that; I just don't think they are conclusive :-) | On the other hand, how do you propose to make up a unique name if an | unnamed enum is used in two different translation units as a template | argument? They are different types, therefore have different internal "names" -- like unnamed namespaces. -- Gaby The C++ working group examined this issue in April as core language issue 488: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#488 They tentatively concluded that type deduction should fail in this case, leaving the built-in operator==(int,int) version as the only viable candidate and thus the code attached to this bug report would compile. It seems likely that this decision will hold, that the standard will be clarified, making this code valid. Can we get this bug re-opened, and perhaps change GCC 4 to accept this code in anticipation of the C++ standard changing to explicitly allow it? Reopening to ... To suspend it as the DR is still in drafting. Subject: Re: error: '<anonymous enum>' is/uses anonymous type'
sethml at google dot com wrote:
> ------- Additional Comments From sethml at google dot com 2005-08-05 03:43 -------
> The C++ working group examined this issue in April as core language issue 488:
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#488
>
> They tentatively concluded that type deduction should fail in this case, leaving
> the built-in operator==(int,int) version as the only viable candidate and thus
> the code attached to this bug report would compile.
>
> It seems likely that this decision will hold, that the standard will be
> clarified, making this code valid.
>
> Can we get this bug re-opened, and perhaps change GCC 4 to accept this code in
> anticipation of the C++ standard changing to explicitly allow it?
Our normal practice has been not to do that until the issue is in at
least WP status.
Created attachment 9998 [details]
tentative patch
From the discussion at the Mont Tremblant meeting, it sounds like we are going to change the language to allow the use of anonymous types as template arguments. Possible patch attached. Subject: Re: [DR 488] error: '<anonymous enum>' is/uses anonymous
type'
jason at gcc dot gnu dot org wrote:
> ------- Comment #18 from jason at gcc dot gnu dot org 2005-10-16 03:57 -------
> Created an attachment (id=9998)
> --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9998&action=view)
> tentative patch
That looks plausible to me, but I guess as this is a C++ ABI change, we
ought to run it past that group too, before implementing it.
*** Bug 27560 has been marked as a duplicate of this bug. *** This was fixed in 4.0.2. *** This bug has been marked as a duplicate of 21514 *** *** Bug 260998 has been marked as a duplicate of this bug. *** Seen from the domain http://volichat.com Page where seen: http://volichat.com/adult-chat-rooms Marked for reference. Resolved as fixed @bugzilla. |