🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1356

g++ internal compiler error 180

#1356
From: jimc
Date: Thu, 07 Jan 1993 03:15
79 lines
2541 bytes
Gnu g++ v2.3.3 for Sparc-SunOS-4.1.1

When a pointer-to-function (not member function) was initialized with
a template function name, the compiler got an internal error 180.

James F. Carter        (213) 825-2897
UCLA-Mathnet;  6221 MSA; 405 Hilgard Ave.; Los Angeles, CA, USA  90024-1555
Internet: jimc@math.ucla.edu            BITNET: jimc%math.ucla.edu@INTERBIT
UUCP:...!{ucsd,ames,ncar,gatech,purdue,rutgers,decvax,uunet}!math.ucla.edu!jimc


-------- Source file

//  bug18.C -- Internal compiler error 180

// g++ v2.3.3 for Sparc-SunOS-4.1.1
// Command line: g++ bug18.C

// bug18.C: In function `int  main ()':
// bug18.C:61: Internal compiler error 180.
// bug18.C:61: Please report this to `bug-g++@prep.ai.mit.edu'.


#include <stdlib.h>
#include <iostream.h>

template<class T>
class data {
    int siz;
    T* stuff;
  public:
    data(int n) : siz(n), stuff(new T[n]) { }
    ~data()
	{ delete stuff; }
    int dim() const
	{ return siz; }
    const T& operator [] (int i) const
	{ return stuff[i]; }
    T& operator [] (int i)
	{ return stuff[i]; }
    static int compare(const T* a, const T* b)
	{ return (int)(*a - *b); }	//Nasty surprise if T=double
    friend ostream& operator << (ostream& f, const data<T>& d);
    void sortme()
	{ qsort(stuff, dim(), sizeof(T), compare); }
//kab.C:26: warning: contravariance violation for method types ignored
};

template <class T> ostream& operator << (ostream& f, const data<T>& d) {
    for (int i = 0; i < d.dim(); ++i)
	f << d[i] << ' ';
    return f;
}
	
template<class T>
int compare(T* a, T* b){ return *a - *b; }

template<class T>
void sort( data<T>d, int (*compare)(T*,T*) )
{ 
     qsort(&(d[0]), d.dim(), sizeof(T), compare); 
}

main(){
	data<int> d(5);
	for (int i = 0; i < d.dim(); ++i)
	    d[i] = d.dim() - i;
	cout << "Before\t" << d << '\n';
//	d.sortme();	// Works

//	sort(d, compare);
//		 type unification failed for function template `sort'
//		(probably ought to be able to figure this one out)

	int (*cptr)(int*,int*) = compare;	//Internal compiler err 180
	sort (d, cptr);

	cout << "After\t" << d << '\n';
}
Technical Details
Message-ID: <9301071915.AA06699@malibu.pic.ucla.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pic.ucla.edu!jimc

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pic.ucla.edu!jimc
From: jimc@pic.ucla.edu
Subject: g++ internal compiler error 180
Message-ID: <9301071915.AA06699@malibu.pic.ucla.edu>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Thu, 7 Jan 1993 03:15:31 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 81