Bug 27560 - template function not recognized when invoked with enum defined in function
Summary: template function not recognized when invoked with enum defined in function
Status: RESOLVED DUPLICATE of bug 20589
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-11 15:43 UTC by Ian Lance Taylor
Modified: 2009-11-04 20:16 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lance Taylor 2006-05-11 15:43:49 UTC
Compiling this file, with mainline, gcc 4.0, or 4.1

template<typename t> void f(t a) { }
void g() { enum e { v }; f(v); }

gives this error message:

foo.cc: In function ‘void g()’:
foo.cc:2: error: no matching function for call to ‘f(g()::e)’

If the enum definition is moved out of the function, this works.  With gcc 3.2, this works.  I didn't try 3.4.

My C++ fu is weak, and I do not know for sure that this is valid C++, although I don't see anything wrong with it.  But either 1) it is valid and gcc should accept it, or 2) gcc should provide a list of candidates which did not match, since there is manifestly a function named 'f'.
Comment 1 Andrew Pinski 2006-05-11 15:58:24 UTC
This is not valid, the type is a local type which causes it be rejected for templates.  The same happens with local classes.
Comment 2 Andrew Pinski 2006-05-11 16:07:44 UTC
14.3.1/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 atemplate-argument for a template type-parameter.
Comment 3 Gabriel Dos Reis 2006-05-11 16:24:07 UTC
Subject: Re:   New: template function not recognized when invoked with enum defined in function

"ian at airs dot com" <gcc-bugzilla@gcc.gnu.org> writes:

| Compiling this file, with mainline, gcc 4.0, or 4.1
| 
| template<typename t> void f(t a) { }
| void g() { enum e { v }; f(v); }
| 
| gives this error message:
| 
| foo.cc: In function ‘void g()’:
| foo.cc:2: error: no matching function for call to ‘f(g()::e)’
| 
| If the enum definition is moved out of the function, this works.  With gcc 3.2,
| this works.  I didn't try 3.4.

There is a core issue for this.  We discussed it again at the last
meeting in Berlin.  There are proposals to make it "just work", but
that is still in the open state.

-- Gaby
Comment 4 Gabriel Dos Reis 2006-05-11 16:33:34 UTC
See

   http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#488
   http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1945.pdf

The later paper is under active consideration.

The PR should be suspended, instead of being hastly closed.
Comment 5 Andrew Pinski 2006-05-11 16:38:34 UTC
(In reply to comment #4)
> The PR should be suspended, instead of being hastly closed.

It was not hastly closed, the current standard says this is invalid.

Anyways there is already a PR open about DR 488.

*** This bug has been marked as a duplicate of 20589 ***
Comment 6 Gabriel Dos Reis 2006-05-11 16:47:54 UTC
Subject: Re:  template function not recognized when invoked with enum defined in function

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| It was not hastly closed, the current standard says this is invalid.

and the current standard is known to be defective in that aspect,
which is why we had the core issue in the first place. 

-- Gaby
Comment 7 Ian Lance Taylor 2006-05-11 22:55:53 UTC
PR 20589 seems to be about an unnamed enum.

This enum in this test case is not unnamed.  It is local to a function, but has a name.

This may be related to 20589, but I don't think it is the same issue.
Comment 8 Andrew Pinski 2006-05-11 23:03:09 UTC
(In reply to comment #7)
> This may be related to 20589, but I don't think it is the same issue.
It is the same issue because there is only one Defect report for the C++ standard.
Comment 9 Gabriel Dos Reis 2006-05-11 23:20:09 UTC
Subject: Re:  template function not recognized when invoked with enum defined in function

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| (In reply to comment #7)
| > This may be related to 20589, but I don't think it is the same issue.
| It is the same issue because there is only one Defect report for the C++
| standard.

They are not the same thing. 

However, somehow, both issues have been conglomerated in the same
_topic_ 

-- Gaby
Comment 10 Jason Merrill 2009-11-04 20:16:24 UTC
In 4.5 this will compile with -std=c++0x.