This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition
- From: "reichelt at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Aug 2004 14:07:30 -0000
- Subject: [Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition
- References: <20040824124058.17166.guillaume.melquiond@ens-lyon.fr>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From reichelt at gcc dot gnu dot org 2004-08-24 14:06 -------
It's a little complicated, but IMHO g++ behaves right:
Everything boils down to the following:
=====================================================
#include<vector>
#include<algorithm>
enum { FOGGED = '~' };
void foo()
{
std::vector<char> v;
std::remove(v.begin(), v.end(), FOGGED);
}
=====================================================
Compiling this I get:
bug.cc: In function `void foo()':
bug.cc:9: error: cannot convert `__gnu_cxx::__normal_iterator<char*,
std::vector<char, std::allocator<char> > >' to `const char*' for argument `1' to
`int remove(const char*)'
The point is that FOGGED is from an anonymous enum which can't be a
template parameter. Just give a name to the enum, and it works fine:
enum E { FOGGED = '~' };
Alternatively you can make a cast to something with a name:
std::remove(v.begin(), v.end(), (char)FOGGED);
Your suggestion unexpectedly works in a similar way. By writing
typedef __typeof__ FOGGED element;
the enum gets a name and the code can be compiled:
=====================================================
#include<vector>
#include<algorithm>
enum { FOGGED = '~' };
void foo()
{
std::vector<char> v;
typedef __typeof__ FOGGED element;
std::remove(v.begin(), v.end(), FOGGED);
}
=====================================================
In essence, g++ is right IMHO, but the error message isn't very helpful...
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |reichelt at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166