home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / gnu / g / bug / 2170 < prev    next >
Encoding:
Text File  |  1993-01-08  |  2.4 KB  |  94 lines

  1. Newsgroups: gnu.g++.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!pic.ucla.edu!jimc
  3. From: jimc@pic.ucla.edu
  4. Subject: g++ internal compiler error 180
  5. Message-ID: <9301071915.AA06699@malibu.pic.ucla.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Thu, 7 Jan 1993 03:15:31 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 81
  12.  
  13. Gnu g++ v2.3.3 for Sparc-SunOS-4.1.1
  14.  
  15. When a pointer-to-function (not member function) was initialized with
  16. a template function name, the compiler got an internal error 180.
  17.  
  18. James F. Carter        (213) 825-2897
  19. UCLA-Mathnet;  6221 MSA; 405 Hilgard Ave.; Los Angeles, CA, USA  90024-1555
  20. Internet: jimc@math.ucla.edu            BITNET: jimc%math.ucla.edu@INTERBIT
  21. UUCP:...!{ucsd,ames,ncar,gatech,purdue,rutgers,decvax,uunet}!math.ucla.edu!jimc
  22.  
  23.  
  24. -------- Source file
  25.  
  26. //  bug18.C -- Internal compiler error 180
  27.  
  28. // g++ v2.3.3 for Sparc-SunOS-4.1.1
  29. // Command line: g++ bug18.C
  30.  
  31. // bug18.C: In function `int  main ()':
  32. // bug18.C:61: Internal compiler error 180.
  33. // bug18.C:61: Please report this to `bug-g++@prep.ai.mit.edu'.
  34.  
  35.  
  36. #include <stdlib.h>
  37. #include <iostream.h>
  38.  
  39. template<class T>
  40. class data {
  41.     int siz;
  42.     T* stuff;
  43.   public:
  44.     data(int n) : siz(n), stuff(new T[n]) { }
  45.     ~data()
  46.     { delete stuff; }
  47.     int dim() const
  48.     { return siz; }
  49.     const T& operator [] (int i) const
  50.     { return stuff[i]; }
  51.     T& operator [] (int i)
  52.     { return stuff[i]; }
  53.     static int compare(const T* a, const T* b)
  54.     { return (int)(*a - *b); }    //Nasty surprise if T=double
  55.     friend ostream& operator << (ostream& f, const data<T>& d);
  56.     void sortme()
  57.     { qsort(stuff, dim(), sizeof(T), compare); }
  58. //kab.C:26: warning: contravariance violation for method types ignored
  59. };
  60.  
  61. template <class T> ostream& operator << (ostream& f, const data<T>& d) {
  62.     for (int i = 0; i < d.dim(); ++i)
  63.     f << d[i] << ' ';
  64.     return f;
  65. }
  66.     
  67. template<class T>
  68. int compare(T* a, T* b){ return *a - *b; }
  69.  
  70. template<class T>
  71. void sort( data<T>d, int (*compare)(T*,T*) )
  72.      qsort(&(d[0]), d.dim(), sizeof(T), compare); 
  73. }
  74.  
  75. main(){
  76.     data<int> d(5);
  77.     for (int i = 0; i < d.dim(); ++i)
  78.         d[i] = d.dim() - i;
  79.     cout << "Before\t" << d << '\n';
  80. //    d.sortme();    // Works
  81.  
  82. //    sort(d, compare);
  83. //         type unification failed for function template `sort'
  84. //        (probably ought to be able to figure this one out)
  85.  
  86.     int (*cptr)(int*,int*) = compare;    //Internal compiler err 180
  87.     sort (d, cptr);
  88.  
  89.     cout << "After\t" << d << '\n';
  90. }
  91.  
  92.  
  93.