home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16676 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.8 KB  |  79 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!usc!rpi!batcomputer!cornell!moudgill
  3. From: moudgill@cs.cornell.edu ( Mayan Moudgill)
  4. Subject: Is there a workaround for this bug?
  5. Message-ID: <1992Nov20.221252.653@cs.cornell.edu>
  6. Summary: parser bug for templates
  7. Keywords: template, bug, example, 3.01
  8. Organization: Cornell Univ. CS Dept, Ithaca NY 14853
  9. Date: Fri, 20 Nov 1992 22:12:52 GMT
  10. Lines: 67
  11.  
  12. I discovered what appears to be a bug in the AT&T C++ 3.01 compiler.
  13. I've included two files which demonstrate it. The first one compiles
  14. correctly, the second doesn't. Both files declare a particular inline
  15. function. The first one defines it inside the class, and it compiles
  16. correctly. The second defines it below the class, and it does not compile.
  17. If it *IS* a bug, who should I report it to.
  18.  
  19. *Please* reply be e-mail. Thanks,
  20. :)
  21. Mayan
  22.  
  23. ------------- CUT HERE FOR CORRECT PROGRAM -------------------
  24. template <unsigned sz> class Vector;
  25. template <unsigned sz> class VectorBind;
  26.  
  27. template <unsigned sz>
  28. class VectorBind {
  29. public:
  30.    inline  VectorBind()
  31.       {
  32.       }
  33. };
  34.  
  35. template <unsigned sz>
  36. class Vector {
  37. public:
  38.    inline VectorBind<sz>    operator [] (unsigned)
  39.    {
  40.       return VectorBind<sz>();
  41.    }
  42. };
  43.  
  44. main()
  45. {
  46. Vector<16u>  v;
  47.     (void)v[8];
  48. }
  49.  
  50. ------------- CUT HERE FOR INCORRECT PROGRAM -------------------
  51. template <unsigned sz> class Vector;
  52. template <unsigned sz> class VectorBind;
  53.  
  54. template <unsigned sz>
  55. class VectorBind {
  56. public:
  57.    inline              VectorBind()
  58.       {
  59.       }
  60. };
  61.  
  62. template <unsigned sz>
  63. class Vector {
  64. public:
  65.    inline VectorBind<sz>    operator [] (unsigned);
  66. };
  67.  
  68. template <unsigned sz>
  69. inline VectorBind<sz>     Vector<sz>::operator [] (unsigned val)
  70. {
  71.    return VectorBind<sz>();
  72. }
  73.  
  74. main()
  75. {
  76. Vector<16u>  v;
  77.     (void)v[8];
  78. }
  79.