home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / bug / 2348 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.1 KB  |  69 lines

  1. Path: sparky!uunet!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!lri.FR!yb
  2. From: yb@lri.FR
  3. Newsgroups: gnu.g++.bug
  4. Subject: badly generated operator new in template
  5. Date: 26 Jan 1993 22:06:10 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 56
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-g++@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <199301261525.AA26111@lri.lri.fr>
  12.  
  13. g++ 2.3.3 generates incorrect operator new when it is defined in a template class. 
  14. Looking at the assembly code, I noticed that the allocated-size is not loaded
  15. from the good register.
  16.  
  17. The following piece of code illustrates this problem :
  18.  
  19. % cat foo.cc
  20. #include <stddef.h>
  21. #include <stdio.h>
  22.  
  23. template <class T>
  24. class A {
  25. public:
  26.     T v;
  27.     void* operator new (size_t);
  28. };
  29.  
  30. template <class T> void*
  31. A<T> :: operator new (size_t s)
  32. {
  33.     printf ("%d\n", s);
  34.     return new char [s];
  35. }
  36.  
  37. main ()
  38. {
  39.     printf ("%d\n", sizeof(A<int>));
  40.     A<int>* a = new A<int>;
  41. }
  42. % gcc -v
  43. Reading specs from /usr/local/gnu/lib/gcc-lib/hp700-hpux/2.3.3/specs
  44. gcc version 2.3.3
  45. % gcc foo.cc
  46. % a.out
  47. 4
  48. -278528
  49. Virtual memory exceeded in `new'
  50. ----------------
  51. Interesting !
  52.  
  53. +--------------------------+------------------------------------+
  54. |                          |       E-mail : yb@lri.lri.fr       |
  55. |     Yves Berteaud        |                yb@FRLRI61.BITNET   |
  56. |                          |                                    |
  57. |       +-=-+-=-+          |       Voice :  33 (1) 69-41-69-10  |
  58. |                          |       Fax   :  33 (1) 69-41-65-86  |
  59. +--------------------------+------------------------------------+
  60. |      ######      **                                           |
  61. |     ##     #         Laboratoire de recherche en informatique |
  62. |    ##       #   ##   Batiment 490                             |
  63. |   ##       #   ##    Universite de Paris-Sud                  |
  64. |  ##    ####   ##     91405 ORSAY Cedex                        |
  65. | ######    ## ##      FRANCE                                   |
  66. |######      ###                                                |
  67. +---------------------------------------------------------------+
  68.  
  69.