Internal Compiler Error
Kevin Smith
kevin@mtsu.edu
Tue Mar 2 21:39:00 GMT 1999
Here is a bug I have come across. I don't know if you are already aware
of this problem, but it said to email you, so I'm going to... :)
First the error:
-- begin: error --
[kevin@ci1002641-a test]$ g++ ola3.cc -o ola3
In file included from ola3.cc:23:
dataType.h:170: Internal compiler error.
dataType.h:170: Please submit a full bug report to `egcs-bugs@cygnus.com'.
-- end: error --
Then the description:
-- begin: description --
Error occurs trying to overload the stream operators (as a friend)
from a templated class
-- end: description --
And the source it is crashing on:
-- begin: dataType.h --
/*
*************************************************************
NAME: dataType.h
AUTHOR: Kevin Smith <kevin@mtsu.edu>
*************************************************************
REMARKS:
This is a generic dataType class
that keeps track of comparisons and
other useful information.
This document largely based on data.h,
provided by Dr. Richard Detmer, MTSU.
*************************************************************
*/
#ifndef __DATATYPE_H
#define __DATATYPE_H
#include <iostream.h>
template <class T>
class dataType
{
public:
/* default constructor */
dataType();
/* copy constructor */
dataType(const dataType<T>& rhs);
/* public member functions */
void setValue(const T& newValue);
/* overloaded comparison operators */
bool operator < (const dataType<T>& rhs) const;
bool operator <= (const dataType<T>& rhs) const;
bool operator > (const dataType<T>& rhs) const;
bool operator >= (const dataType<T>& rhs) const;
bool operator == (const dataType<T>& rhs) const;
bool operator != (const dataType<T>& rhs) const;
/* overloaded assignment operators */
dataType<T>& operator = (const dataType<T>& rhs);
/* overloaded input stream operators (not templated) */
friend istream& operator >> <> (istream &is, dataType<T>& rhs);
/* overloaded output stream operators (not templated) */
friend ostream& operator << <> (ostream &os, const dataType<T>& rhs);
private:
T data;
};
/* Count statistics variables */
unsigned long int lessCount;
unsigned long int equalCount;
unsigned long int notEqualCount;
unsigned long int greaterCount;
unsigned long int assignCount;
// NAME: dataType()
// PURPOSE: default constructor
// REMARKS:
template <class T>
dataType<T>::dataType()
{
// nothing to do here
}
// NAME: dataType()
// PURPOSE: copy constructor
// REMARKS:
template <class T>
dataType<T>::dataType(const dataType<T>& rhs)
{
data=rhs.data;
}
// NAME: setValue()
// PURPOSE: set the value of data to the value of T
// REMARKS:
template <class T>
void dataType<T>::setValue(const T& newValue)
{
data=newValue;
}
// NAME: operator <
// PURPOSE: overloaded comparison operator
// REMARKS: performs comparison, and increments lessCount
template <class T>
bool dataType<T>::operator <(const dataType<T>& rhs) const
{
lessCount++;
return( data < rhs.data );
}
// NAME: operator <=
// PURPOSE: overloaded comparison operator
// REMARKS: performs comparison, and increments lessCount and equalCount
template <class T>
bool dataType<T>::operator <=(const dataType<T>& rhs) const
{
lessCount++;
equalCount++;
return( data <= rhs.data );
}
// NAME: operator >
// PURPOSE: overloaded comparison operator
// REMARKS: performs comparison, and increments greaterCount
template <class T>
bool dataType<T>::operator >(const dataType<T>& rhs) const
{
greaterCount++;
return( data > rhs.data );
}
// NAME: operator >=
// PURPOSE: overloaded comparison operator
// REMARKS: performs comparison, and increments greaterCount and equalCount
template <class T>
bool dataType<T>::operator >=(const dataType<T>& rhs) const
{
greaterCount++;
equalCount++;
return( data >= rhs.data );
}
// NAME: operator ==
// PURPOSE: overloaded comparison operator
// REMARKS: performs comparison, and increments equalCount
template <class T>
bool dataType<T>::operator ==(const dataType<T>& rhs) const
{
equalCount++;
return( data == rhs.data );
}
// NAME: operator !=
// PURPOSE: overloded comparison operator
// REMARKS: performs comparison, and increments notEqualCount
template <class T>
bool dataType<T>::operator !=(const dataType<T>& rhs) const
{
notEqualCount++;
return( data != rhs.data );
}
// NAME: operator =
// PURPOSE: overloaded assignment operator
// REMARKS: performs assignment, increments assignCount, returns lvalue
template <class T>
dataType<T>& dataType<T>::operator =(const dataType<T>& rhs)
{
assignCount++;
data = rhs.data;
return *this;
}
// NAME: >>
// PURPOSE: overloaded istream operator
// REMARKS: unfortunately, not templated as of yet
template <class T>
istream& operator >> <> (istream &is, dataType<T>& rhs)
{
is >> rhs.data;
return is;
}
// NAME: <<
// PURPOSE: overloaded ostream operator
// REMARKS: unfortunately, not templated yet
template <class T>
ostream& operator << <> (ostream &os, const dataType<T>& rhs)
{
os << rhs.data;
return os;
}
#endif
/*
*************************************************************
-- E O F --
*************************************************************
*/
-- end: dataType.h --
Perhaps I am just doing something incorrectly, I certainly hope so.. :) I
get the same exact error message (different email address to report to)
with the gnu c++ compiler, but it compiles (and works) properly using the
HP-UX 11.0 aCC compiler...
Either way, I would appreciate knowing what develops of this...
-----
Kevin Smith
kevin@mtsu.edu
Four thousand throats may be cut in one night by a running man.
-- Klingon Soldier, "Day of the Dove", stardate unknown
More information about the Gcc-bugs
mailing list