home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / g / bug / 1855 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.6 KB  |  75 lines

  1. Newsgroups: gnu.g++.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!icsi.berkeley.edu!krste
  3. From: krste@icsi.berkeley.edu (Krste Asanovic)
  4. Subject: template constructors with argument bug.
  5. Message-ID: <9211210416.AA27828@icsib43.ICSI.Berkeley.EDU>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Sat, 21 Nov 1992 04:16:51 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 62
  12.  
  13. The following transcript shows a C++ program using templates that gets
  14. a fatal signal with gcc-2.3.1, but compiles OK with gcc-2.2.2. This is
  15. on a SPARC running SunOS Release 4.1.1.
  16.  
  17. Krste Asanovic,                   Computer Science Division, 
  18. email: krste@cs.berkeley.edu      c/o 571 Evans Hall
  19. phone: +1 (510) 642-4274 ext 143  University of California at Berkeley
  20. fax:   +1 (510) 643-7684          CA 94720, USA
  21.  
  22. ----------------------------------------------------------------------
  23.  
  24. icsib43:src>cat main.cc
  25. template<class T>
  26. class Vec
  27. {
  28. public:
  29.     Vec(int nElements);
  30.     ~Vec();
  31.  
  32.     int size();
  33.  
  34. protected:
  35.     int n;
  36.     T *p;
  37. };
  38.  
  39. template<class T>
  40. inline
  41. Vec<T>::Vec(int nElements)
  42.   : n(nElements)
  43. {
  44.     p = new T[nElements];
  45. }
  46.  
  47. template<class T>
  48. inline
  49. Vec<T>::~Vec()
  50. {
  51.     delete[] p;
  52. }
  53.  
  54. template<class T>
  55. inline int
  56. Vec<T>::size()
  57. {
  58.     return n;
  59. }
  60.  
  61. main()
  62. {
  63.     Vec<int> a(3);
  64.  
  65.     return 0;
  66. }
  67. icsib43:src>gcc -o main main.cc
  68. main.cc: In function `int  main ()':
  69. main.cc:13: inconsistent return types for method `Vec' in class `Vec<int>'
  70. gcc: Internal compiler error: program cc1plus got fatal signal 11
  71. icsib43:src>gcc -V2.2.2 -o main main.cc
  72. icsib43:src>
  73.  
  74.  
  75.