This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]