Bug 20589 - [DR 488] error: '<anonymous enum>' is/uses anonymous type'
Summary: [DR 488] error: '<anonymous enum>' is/uses anonymous type'
Status: RESOLVED DUPLICATE of bug 21514
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 27560 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-22 15:45 UTC by Caolan McNamara
Modified: 2014-02-16 13:13 UTC (History)
10 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-01-15 21:04:13


Attachments
example (156 bytes, text/x-csrc)
2005-03-22 15:46 UTC, Caolan McNamara
Details
tentative patch (837 bytes, patch)
2005-10-16 03:57 UTC, Jason Merrill
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caolan McNamara 2005-03-22 15:45:42 UTC
g++ -c the attached example with 4.0 gives the above error. Is this expected
behaviour ?
Comment 1 Caolan McNamara 2005-03-22 15:46:10 UTC
Created attachment 8433 [details]
example
Comment 2 Andrew Pinski 2005-03-22 16:09:20 UTC
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?
Comment 3 Mark Mitchell 2005-03-22 16:16:12 UTC
Yes, this is invalid code, as the template parameters involve an anonymous type.
Comment 4 Caolan McNamara 2005-03-23 11:53:39 UTC
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.
Comment 5 Andrew Pinski 2005-03-23 16:57:17 UTC
(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.
Comment 6 Wolfgang Bangerth 2005-03-23 18:53:03 UTC
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 
 
Comment 7 Caolan McNamara 2005-03-23 19:12:45 UTC
Sounds reasonable, but it's not the case that the compiler should just silently
not consider anonymous enums as candidates for template argument matching ? 
Comment 8 Wolfgang Bangerth 2005-03-23 19:24:26 UTC
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. 
Comment 9 Mark Mitchell 2005-03-23 19:28:49 UTC
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.

Comment 10 Wolfgang Bangerth 2005-03-23 21:56:34 UTC
Related PRs are: PR 19404, and in particular PR 17413. The latter is the one 
I was thinking of. 
 
W. 
Comment 11 Gabriel Dos Reis 2005-03-26 04:20:02 UTC
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
Comment 12 Wolfgang Bangerth 2005-03-26 22:53:08 UTC
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. 
Comment 13 Gabriel Dos Reis 2005-03-27 03:18:28 UTC
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
Comment 14 Seth LaForge 2005-08-05 03:43:36 UTC
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?
Comment 15 Andrew Pinski 2005-08-05 03:48:15 UTC
Reopening to ...
Comment 16 Andrew Pinski 2005-08-05 03:48:43 UTC
To suspend it as the DR is still in drafting.
Comment 17 Mark Mitchell 2005-08-05 03:49:38 UTC
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.

Comment 18 Jason Merrill 2005-10-16 03:57:05 UTC
Created attachment 9998 [details]
tentative patch
Comment 19 Jason Merrill 2005-10-16 03:57:47 UTC
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.
Comment 20 Mark Mitchell 2005-10-16 17:16:44 UTC
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.

Comment 21 Andrew Pinski 2006-05-11 16:38:34 UTC
*** Bug 27560 has been marked as a duplicate of this bug. ***
Comment 22 Jason Merrill 2009-11-04 20:40:46 UTC
This was fixed in 4.0.2.

*** This bug has been marked as a duplicate of 21514 ***
Comment 23 Jackie Rosen 2014-02-16 13:13:52 UTC Comment hidden (spam)