* g++ Template call through pointer - a bug?
@ 2005-04-05 22:06 Vladimir Avdonin
2005-04-05 22:18 ` Stefan Strasser
2005-06-26 2:16 ` Problem with g++ 4.0 Luiz Rafael Culik Guimaraes
0 siblings, 2 replies; 3+ messages in thread
From: Vladimir Avdonin @ 2005-04-05 22:06 UTC (permalink / raw)
To: gcc-help
Hi,
Here is a short program that fail to compile with single error that I can not
explain. Here I try to call a member function template via pointer to object.
Seemingly the same code compiles in one context and fails in other with syntax
error. I would not claim this is a bug, but it does look like one to me. What
am I missing here? gcc version 3.3.3 (mingw special)
Thanks
Vladimir
-------------------------
#include <stdio.h>
struct A {
template <class T> void fun() {
printf("%d\n",sizeof(T));
}
};
struct B {
A *a;
B(A *ia) {
a = ia;
}
template <class T> void fun() {
a->fun<T>(); // This works
}
};
template <class T> void ptrfun(A* a) {
a->fun<T>(); // tst.cpp:19: error: syntax error before `>' token
}
int main() {
A a;
B b(&a);
a.fun<int>();
b.fun<double>();
ptrfun<char>(&a);
}
-------------------------------------------
__________________________________
Yahoo! Messenger
Show us what our next emoticon should look like. Join the fun.
http://www.advision.webevents.yahoo.com/emoticontest
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: g++ Template call through pointer - a bug?
2005-04-05 22:06 g++ Template call through pointer - a bug? Vladimir Avdonin
@ 2005-04-05 22:18 ` Stefan Strasser
2005-06-26 2:16 ` Problem with g++ 4.0 Luiz Rafael Culik Guimaraes
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Strasser @ 2005-04-05 22:18 UTC (permalink / raw)
To: gcc-help; +Cc: Vladimir Avdonin
Vladimir Avdonin schrieb:
> template <class T> void ptrfun(A* a) {
> a->fun<T>(); // tst.cpp:19: error: syntax error before `>' token
> }
>
fixed in 3.4.
use "a->template fun<T>()" as a workaround.
--
Stefan Strasser
^ permalink raw reply [flat|nested] 3+ messages in thread
* Problem with g++ 4.0
2005-04-05 22:06 g++ Template call through pointer - a bug? Vladimir Avdonin
2005-04-05 22:18 ` Stefan Strasser
@ 2005-06-26 2:16 ` Luiz Rafael Culik Guimaraes
1 sibling, 0 replies; 3+ messages in thread
From: Luiz Rafael Culik Guimaraes @ 2005-06-26 2:16 UTC (permalink / raw)
To: gcc-help
Dear Friends
I has one c++ code that use this declaration bellow
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipCollections.h $
// $Archive: /ZipArchive_STL/ZipCollections.h $
// $Date: 21-01-04 19:05 $ $Author: Tadeusz Dracz $
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution
and
// is Copyright 2000-2004 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#ifndef ZIPCOLLECTIONS_DOT_H
#define ZIPCOLLECTIONS_DOT_H
#if _MSC_VER > 1000
#pragma warning( push, 3 ) // STL "requirements"
#pragma warning (disable : 4284) //return type for 'identifier::operator >'
is not a UDT or reference to a UDT. Will produce errors if applied using
infix notation
#pragma warning (disable : 4018) //'expression' : signed/unsigned mismatch
#endif
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include "ZipString.h"
#include "ZipExport.h"
template<class TYPE>
class CZipArray : private std::vector<TYPE>
{
public:
typedef typename std::vector<TYPE>::iterator iterator;
typedef typename std::vector<TYPE> inherited;
protected:
iterator GetIterFromIndex(int uIndex)
{
iterator iter = begin();
iter += uIndex;
// int t = 0; while (t != uIndex) {iter++;t++;}
return iter;
}
public:
void Sort(bool bAscending)
{
if (bAscending)
std::sort (begin (), end (), std::less<TYPE> ());
else
std::sort (begin (), end (), std::greater<TYPE> ());
}
int GetSize() const{return (int)size(); }
int GetUpperBound() const {return size() - 1;}
int Add(const TYPE& x) {push_back(x);return GetUpperBound();}
void RemoveAll() {clear();}
void RemoveAt(int uIndex) { erase(GetIterFromIndex(uIndex));}
void InsertAt(int uIndex, const TYPE& x){insert(GetIterFromIndex(uIndex),
x);}
#ifndef _MSC_VER
TYPE& operator[](int iIndex)
{
return inherited::operator[](iIndex);
}
TYPE operator[](int iIndex) const
{
return inherited::operator[](iIndex);
}
#else
using inherited::operator[];
#endif
};
typedef CZipArray<CZipString> CZipStringArray;
typedef CZipArray<WORD> CZipWordArray;
template<class TYPE>
class ZIP_API CZipPtrList : private std::list<TYPE>
{
public:
typedef typename std::list<TYPE>::iterator iterator;
typedef typename std::list<TYPE>::const_iterator const_iterator;
int GetCount() const {return size();}
void AddTail(const TYPE& x){push_back(x);}
void AddHead(const TYPE& x){push_front(x);}
void RemoveHead() {pop_front();}
void RemoveTail() {pop_back();}
void RemoveAll() {clear();}
TYPE& GetHead() {return front();}
TYPE GetHead() const {return front();}
TYPE& GetTail() {return back();}
TYPE GetTail() const {return back();}
iterator GetHeadPosition() { return begin();}
const_iterator GetHeadPosition() const { return begin();}
iterator GetTailPosition() { return back();}
TYPE& GetNext(iterator& pos) { return *pos++;}
const TYPE GetNext(const_iterator& pos) const{ return *pos++;}
TYPE& GetPrev(iterator& pos) { return *pos--;}
TYPE GetPrev(iterator& pos) const{ return *pos--;}
iterator Find(TYPE& x) { return std::find(begin(), end(), x);}
void RemoveAt(iterator& pos) { erase(pos);}
bool IteratorValid(const_iterator &iter) const
{
return iter != end();
}
bool IteratorValid(iterator &iter)
{
return iter != end();
}
iterator FindIndex(int iIndex)
{
iterator iter = begin();
int t = 0; while (t != iIndex) {iter++;t++;}
return iter;
}
const_iterator FindIndex(int iIndex) const
{
const_iterator iter = begin();
int t = 0; while (t != iIndex) {iter++;t++;}
return iter;
}
TYPE& GetAt(const iterator& pos) { return *pos;}
TYPE GetAt(const_iterator& pos) const{ return *pos;}
};
// simplified and partial only
template<class KEY, class VALUE>
class ZIP_API CZipMap : private std::map<KEY, VALUE>
{
public:
typedef typename std::map<KEY, VALUE>::const_iterator const_iterator;
void SetAt( KEY key, VALUE newValue)
{
insert(std::map<KEY, VALUE>::value_type(key, newValue));
}
BOOL RemoveKey( KEY key )
{
return erase(key) != 0;
}
BOOL Lookup( KEY key, VALUE& rValue ) const
{
const_iterator iter = find(key);
if (iter == end())
return FALSE;
else
{
rValue = iter->second;
return TRUE;
}
}
};
#if defined(_MSC_VER) && (_MSC_VER > 1100)
#pragma warning( pop)
#endif
#endif /* ZIPCOLLECTIONS_DOT_H */
With gcc 3.3.x i compile with out any problem the code
but with gcc 4.0 i get this erros
g++ -fpermissive -c -I. ZipArchive.cpp
ZipCollections.h: In member function 'typename std::vector<TYPE,
std::allocator<_CharT> >::iterator CZipArray<TYPE>::GetIterFromIndex(int)':
ZipCollections.h:44: warning: there are no arguments to 'begin' that depend
on a template parameter, so a declaration of 'begin' must be available
ZipCollections.h: In member function 'void CZipArray<TYPE>::Sort(bool)':
ZipCollections.h:53: warning: there are no arguments to 'begin' that depend
on a template parameter, so a declaration of 'begin' must be available
ZipCollections.h:53: warning: there are no arguments to 'end' that depend on
a template parameter, so a declaration of 'end' must be available
ZipCollections.h:55: warning: there are no arguments to 'begin' that depend
on a template parameter, so a declaration of 'begin' must be available
ZipCollections.h:55: warning: there are no arguments to 'end' that depend on
a template parameter, so a declaration of 'end' must be available
ZipCollections.h: In member function 'int CZipArray<TYPE>::GetSize() const':
ZipCollections.h:57: warning: there are no arguments to 'size' that depend
on a template parameter, so a declaration of 'size' must be available
ZipCollections.h: In member function 'int CZipArray<TYPE>::GetUpperBound()
const':
ZipCollections.h:58: warning: there are no arguments to 'size' that depend
on a template parameter, so a declaration of 'size' must be available
ZipCollections.h: In member function 'void CZipArray<TYPE>::RemoveAll()':
ZipCollections.h:60: warning: there are no arguments to 'clear' that depend
on a template parameter, so a declaration of 'clear' must be available
ZipCollections.h: In member function 'int CZipPtrList<TYPE>::GetCount()
const':
ZipCollections.h:89: warning: there are no arguments to 'size' that depend
on a template parameter, so a declaration of 'size' must be available
ZipCollections.h: In member function 'void CZipPtrList<TYPE>::RemoveHead()':
ZipCollections.h:92: warning: there are no arguments to 'pop_front' that
depend on a template parameter, so a declaration of 'pop_front' must be
available
ZipCollections.h: In member function 'void CZipPtrList<TYPE>::RemoveTail()':
ZipCollections.h:93: warning: there are no arguments to 'pop_back' that
depend on a template parameter, so a declaration of 'pop_back' must be
available
ZipCollections.h: In member function 'void CZipPtrList<TYPE>::RemoveAll()':
ZipCollections.h:94: warning: there are no arguments to 'clear' that depend
on a template parameter, so a declaration of 'clear' must be available
ZipCollections.h: In member function 'TYPE& CZipPtrList<TYPE>::GetHead()':
ZipCollections.h:95: warning: there are no arguments to 'front' that depend
on a template parameter, so a declaration of 'front' must be available
ZipCollections.h: In member function 'TYPE CZipPtrList<TYPE>::GetHead()
const':
ZipCollections.h:96: warning: there are no arguments to 'front' that depend
on a template parameter, so a declaration of 'front' must be available
ZipCollections.h: In member function 'TYPE& CZipPtrList<TYPE>::GetTail()':
ZipCollections.h:97: warning: there are no arguments to 'back' that depend
on a template parameter, so a declaration of 'back' must be available
ZipCollections.h: In member function 'TYPE CZipPtrList<TYPE>::GetTail()
const':
ZipCollections.h:98: warning: there are no arguments to 'back' that depend
on a template parameter, so a declaration of 'back' must be available
ZipCollections.h: In member function 'typename std::list<TYPE,
std::allocator<_CharT> >::iterator CZipPtrList<TYPE>::GetHeadPosition()':
ZipCollections.h:99: warning: there are no arguments to 'begin' that depend
on a template parameter, so a declaration of 'begin' must be available
ZipCollections.h: In member function 'typename std::list<TYPE,
std::allocator<_CharT> >::const_iterator
CZipPtrList<TYPE>::GetHeadPosition() const':
ZipCollections.h:100: warning: there are no arguments to 'begin' that depend
on a template parameter, so a declaration of 'begin' must be available
ZipCollections.h: In member function 'typename std::list<TYPE,
std::allocator<_CharT> >::iterator CZipPtrList<TYPE>::GetTailPosition()':
ZipCollections.h:101: warning: there are no arguments to 'back' that depend
on a template parameter, so a declaration of 'back' must be available
ZipCollections.h: In member function 'typename std::list<TYPE,
std::allocator<_CharT> >::iterator CZipPtrList<TYPE>::Find(TYPE&)':
ZipCollections.h:106: warning: there are no arguments to 'begin' that depend
on a template parameter, so a declaration of 'begin' must be available
ZipCollections.h:106: warning: there are no arguments to 'end' that depend
on a template parameter, so a declaration of 'end' must be available
ZipCollections.h: In member function 'bool
CZipPtrList<TYPE>::IteratorValid(typename std::list<TYPE,
std::allocator<_CharT> >::const_iterator&) const':
ZipCollections.h:110: warning: there are no arguments to 'end' that depend
on a template parameter, so a declaration of 'end' must be available
ZipCollections.h: In member function 'bool
CZipPtrList<TYPE>::IteratorValid(typename std::list<TYPE,
std::allocator<_CharT> >::iterator&)':
ZipCollections.h:114: warning: there are no arguments to 'end' that depend
on a template parameter, so a declaration of 'end' must be available
ZipCollections.h: In member function 'typename std::list<TYPE,
std::allocator<_CharT> >::iterator CZipPtrList<TYPE>::FindIndex(int)':
ZipCollections.h:118: warning: there are no arguments to 'begin' that depend
on a template parameter, so a declaration of 'begin' must be available
ZipCollections.h: In member function 'typename std::list<TYPE,
std::allocator<_CharT> >::const_iterator CZipPtrList<TYPE>::FindIndex(int)
const':
ZipCollections.h:124: warning: there are no arguments to 'begin' that depend
on a template parameter, so a declaration of 'begin' must be available
ZipCollections.h: In member function 'BOOL CZipMap<KEY, VALUE>::Lookup(KEY,
VALUE&) const':
ZipCollections.h:150: warning: there are no arguments to 'end' that depend
on a template parameter, so a declaration of 'end' must be available
ZipCollections.h: In member function 'void CZipMap<KEY, VALUE>::SetAt(KEY,
VALUE) [with KEY = CZipArchive::CallbackType, VALUE = CZipActionCallback*]':
ZipArchive.h:1754: instantiated from here
ZipCollections.h:141: error: dependent-name
'std::map<KEY,VALUE,std::less<_Key>,std::allocator<std::pair<const _Key,
_Tp> > >::value_type' is parsed as a non-type, but instantiation yields a
type
ZipCollections.h:141: note: say 'typename
std::map<KEY,VALUE,std::less<_Key>,std::allocator<std::pair<const _Key, _Tp>
> >::value_type' if a type is meant
make: ** [ZipArchive.o] Erro 1
Can any one help
Regards
Luiz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-06-26 2:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-05 22:06 g++ Template call through pointer - a bug? Vladimir Avdonin
2005-04-05 22:18 ` Stefan Strasser
2005-06-26 2:16 ` Problem with g++ 4.0 Luiz Rafael Culik Guimaraes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).