This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/23755] New: template class inheritance
- From: "compi at freemail dot hu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Sep 2005 20:38:07 -0000
- Subject: [Bug c++/23755] New: template class inheritance
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Inheritance in template classes seems to have a critical bug.
The compliler fails to find both inherited functions and inherited member
variables.
The attached code is compiling fine in gcc-3.3 [g++-3.3 (GCC) 3.3.6 (Debian
1:3.3.6-9)].
g++-4.0 -o main main.cpp
temp_child.h: In member function 'void CFC_tSortArray<TYPE, dwTemplAlloc>::Add
(long int)':
temp_child.h:24: error: there are no arguments to 'InitChk' that depend on a
template parameter, so a declaration of 'InitChk' must be available
temp_child.h:24: error: (if you use '-fpermissive', G++ will accept your code,
but allowing the use of an undeclared name is deprecated)
temp_child.h:25: error: 'm_dwItemCount' was not declared in this scope
make: *** [main] Error 1
The issue first appears in gcc-3.4 [
g++-3.4 (GCC) 3.4.5 20050821 (prerelease) (Debian 3.4.4-8)] and gcc-4.0 [g++-
4.0 (GCC) 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)]
ATTACHED:
temp_base.h
--------------------------------------------------------------------
#ifndef _CFC_ARRAY_H_INCLUDED
#define _CFC_ARRAY_H_INCLUDED
template < class TYPE, long dwTemplAlloc = 0> class CFC_tArray
{
public:
CFC_tArray( long dwAllocItems = 0 )
{
m_pArray = 0;
m_dwItemCount = 0;
}
virtual ~CFC_tArray()
{
if (m_pArray)
{
free(m_pArray);
}
}
inline bool IsActive() const { return m_dwItemCount != 0; };
inline void InitChk () const { if ( !IsActive() ) throw((long)
1); };
protected:
TYPE* m_pArray;
long m_dwItemCount;
};
#endif // _CFC_ARRAY_H_INCLUDED
------------------------------------------------------------------
end of temp_base.h
temp_child.h
------------------------------------------------------------------
#ifndef _CFC_ARRAY1_H_INCLUDED
#define _CFC_ARRAY1_H_INCLUDED
#include "temp_base.h"
template< class TYPE, long dwTemplAlloc = 0 > class CFC_tSortArray : public
CFC_tArray <TYPE, 0>
{
public:
CFC_tSortArray( long dwAllocItems, bool fAutoSort = false, bool
fSortable = false)
{
m_fSortable = fSortable;
m_fAutoSort = fAutoSort;
m_fSorted = false;
}
virtual ~CFC_tSortArray()
{
}
void Add( long a)
{
InitChk();
m_dwItemCount += a;
}
protected:
bool m_fSortable;
bool m_fSorted;
bool m_fAutoSort;
};
#endif // _CFC_ARRAY1_H_INCLUDED
------------------------------------------------------------------
end of temp_child.h
main.cpp
------------------------------------------------------------------
#include <stdlib.h>
#include "temp_child.h"
int main(int argc, char** argv)
{
CFC_tSortArray<long> a(1);
a.Add(12);
return 0;
}
------------------------------------------------------------------
end of main.cpp
--
Summary: template class inheritance
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: compi at freemail dot hu
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23755