home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / win32 / 2442 < prev    next >
Encoding:
Text File  |  1992-12-14  |  10.5 KB  |  383 lines

  1. Newsgroups: comp.os.ms-windows.programmer.win32
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!hellgate.utah.edu!irit.cs.utah.edu!gershon
  3. From: gershon%irit.cs.utah.edu@cs.utah.edu (Elber Gershon)
  4. Subject: NT October release C++ bugs
  5. Date: 14 Dec 92 16:05:58 MST
  6. Message-ID: <1992Dec14.160558.7685@hellgate.utah.edu>
  7. Organization: University of Utah CS Dept
  8. Lines: 373
  9.  
  10. Below are several bugs in the C++ of the beta october release of window NT.
  11. I would appreciate if someone can upload this to Compuserve as Microsoft
  12. requests since I have no such access.
  13.  
  14.     All small programs below fail on the NT C++ compiler but
  15. succeed using unix AT&T 2.1/3.0 C++ as well as Sun and SGI C++ compiler.
  16. All these small examples were extracted from a very large C++ project that
  17. runs under unix for several years. All compiled in NT using 'cl -c -Tp file.c'.
  18.  
  19. thanks
  20.  
  21. Gershon Elber
  22.  
  23. *****************************************************************************
  24. BUG1
  25. *****************************************************************************
  26. #include <stdio.h>                      /* Standard I/O always available. */
  27.  
  28. struct point_type;
  29.  
  30. typedef point_type vector_type;
  31. typedef point_type line_type;
  32. typedef point_type p2pt_type;
  33.  
  34. class point_type
  35. {
  36.     double xyz_[3];
  37. public:
  38.  
  39. public:
  40.     point_type();
  41.     point_type( double px, double py, double pz );
  42.     inline double &x();
  43.     inline double x() const;
  44.     inline double &y();
  45.     inline double y() const;
  46.     inline double &z();
  47.     inline double z() const;
  48.  
  49.     /* Remove this constructore and this file will not fail with
  50.      * INTERNAL COMPILER ERROR
  51.      */
  52.     point_type( const point_type *p );
  53. };
  54.  
  55.  
  56. extern line_type *
  57. line_thru_2pts( const point_type *pt1, 
  58.         const point_type *pt2,
  59.         line_type *res = NULL );
  60.  
  61.  
  62. void
  63. compute_visib_bound()
  64. {
  65.     int i;
  66.     line_type l;
  67.  
  68.     for ( i = 0; i < 10; i++ )
  69.     {
  70.     point_type pt1, pt2;
  71.     point_type pt = point_type( 1, 2, 3 );
  72.  
  73.     if ( pt.x() > pt.y() )
  74.     {
  75.         pt1 = point_type( ( pt.z() + pt.y() ) / -pt.x(), 1.0, 0.0 );
  76.         pt2 = point_type( ( pt.z() - pt.y() ) / -pt.x(), -1.0, 0.0 );
  77.     }
  78.     else
  79.     {
  80.         pt1 = point_type( 1.0, ( pt.z() + pt.x() ) / -pt.y(), 0.0 );
  81.         pt2 = point_type( -1.0, ( pt.z() - pt.x() ) / -pt.y(), 0.0 );
  82.     }
  83.     l = line_thru_2pts( &pt1, &pt2 );
  84.     }
  85. }
  86. -----------------------------------------------------------------------------
  87. 'cl /c /Tp bug.c' dies:
  88.  
  89. bug.c
  90. bug.c(58) : error C2102: '&' requires lvalue
  91. bug.c(58) : fatal error C1001: INTERNAL COMPILER ERROR
  92.         (compiler file 'msc1.cpp', line 555)
  93.         Contact Microsoft Product Support Services
  94.  
  95.  
  96. The constructor 'point_type( const point_type *p );' is implicitly used
  97. in the assignment of 'l = line_thru_2pts( &pt1, &pt2 );' and these are the
  98. lines that causes it to die.
  99.   This program was successfully compiled using unix AT&T C++.
  100.  
  101. *****************************************************************************
  102. BUG2
  103. *****************************************************************************
  104. #include <stdio.h>
  105.  
  106. class point_type
  107. {
  108. public:
  109.     double xyz[3];
  110.     point_type( double px, double py, double pz );
  111. };
  112.  
  113. typedef point_type vector_type;
  114.  
  115. main()
  116. {
  117.     vector_type v = vector_type( 1, 2, 3 );
  118.  
  119.     printf( "%lf %lf %lf\n", v.xyz[0], v.xyz[1], v.xyz[2] );
  120. }
  121. -----------------------------------------------------------------------------
  122. 'cl /c /Tp bug.c' fails with the following:
  123. bug.c
  124. bug.c(14) : error C2514: 'vector_type' : class has no constructors
  125. bug.c(14) : error C2512: 'point_type' : no appropriate default constructor available
  126. bug.c(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed
  127.  
  128. By typedef'ing vector_type should be identical to point_type.
  129.   This program was successfully compiled using unix AT&T C++.
  130.  
  131. *****************************************************************************
  132. BUG3
  133. *****************************************************************************
  134. #include <stdio.h>
  135.  
  136. class point_type
  137. {
  138.     double xyz_[3];
  139. public:
  140.  
  141. public:
  142.     point_type();
  143.     point_type( double px, double py, double pz );
  144.     point_type( const point_type *p );
  145. };
  146.  
  147. class plane_equation_type
  148. {
  149.     double abcd_[4];
  150. public:
  151.  
  152. public:
  153.     plane_equation_type() {};
  154.     plane_equation_type( double a, double b, double c, double d );
  155.     plane_equation_type( const plane_equation_type *p ); // asserted constructor.
  156. };
  157.  
  158. extern point_type
  159. pt_from_3_planes( const plane_equation_type plane1,
  160.           const plane_equation_type plane2,
  161.           const plane_equation_type plane3 );
  162.  
  163. void 
  164. offset_pt_normals()
  165. {
  166.     plane_equation_type planes[3];
  167.     point_type p = pt_from_3_planes( &planes[0], &planes[1], &planes[2] );
  168. }
  169. -----------------------------------------------------------------------------
  170. 'cl /c /Tp b3.c' dies on this program with:
  171.  
  172. b3.c
  173. Compiler error (assertion): file @(#)typer.c:1.114, line 192 source=34
  174. Compiler error (assertion): file @(#)typer.c:1.114, line 161 source=34
  175. Compiler error (assertion): file @(#)typer.c:1.114, line 192 source=34
  176. Compiler error (assertion): file @(#)typer.c:1.114, line 192 source=34
  177. Compiler error (assertion): file @(#)typer.c:1.114, line 161 source=34
  178. Compiler error (assertion): file @(#)typer.c:1.114, line 192 source=34
  179. b3.c(34) : fatal error C1003: error count exceeds 5; stopping compilation
  180.  
  181. Again, related to the 'plane_equation_type( const plane_equation_type *p );'
  182. constructor from pointer to the object.
  183.  
  184. *****************************************************************************
  185. BUG4
  186. *****************************************************************************
  187. enum domain_span_enum
  188. {
  189.     DOMAIN_SPAN_NONE = 0x00,
  190.     DOMAIN_SPAN_START = 0x01,
  191.     DOMAIN_SPAN_END = 0x02,
  192.     DOMAIN_SPAN_ALL = 0x03
  193. };
  194.  
  195. class point_type
  196. {
  197.     double xyz_[3];
  198. public:
  199.  
  200. public:
  201.     point_type();
  202.     point_type( double px, double py, double pz );
  203.     set_attr( char *nm, int in );
  204.     set_attr( char *nm, double in );
  205.     set_attr( char *nm, char *in );
  206. };
  207.  
  208. void 
  209. bug4()
  210. {
  211.     point_type pt = point_type( 1, 2, 3 );
  212.  
  213.     pt.set_attr( "bug", DOMAIN_SPAN_NONE );
  214. }
  215. -----------------------------------------------------------------------------
  216. 'cl /c /Tp bug4.c' quits with the following message:
  217.  
  218. bug4.c
  219. bug4.c(27) : error C2668: 'set_attr' : ambiguous call to overloaded function
  220.  
  221. The overloaded set_attr function has a match with an integer the enum
  222. should be automatically coerced to.
  223.  
  224. *****************************************************************************
  225. BUG5
  226. *****************************************************************************
  227. #include <stdio.h>
  228. struct address_element_type
  229.  
  230. {
  231.     void *addr;
  232.     void *trans;
  233. };
  234.  
  235. class shared_objects_type : public address_element_type
  236. {
  237.     address_element_type **translation_table;
  238.  
  239. public:
  240.     void           add_translation( void *key,
  241.                     const address_element_type *ent );
  242.     const address_element_type **tmember( void *key ) const;
  243. };
  244.  
  245. void
  246. shared_objects_type::add_translation( void *key,
  247.                       const address_element_type *ent )
  248. {
  249.     const address_element_type **tp;
  250.  
  251.     /* Get a pointer to the hash point. */
  252.     tp = translation_table + ((unsigned int)key >> 5);
  253.  
  254.     /* Perform a linear search for free slots or the target address. */
  255.     for ( int i = 0; i < 120; i++ )
  256.     /* Grab the first free address. */
  257.     if ( *tp == NULL )
  258.     {
  259.         *tp = ent;
  260.         return;
  261.     }
  262.     else if ( ++tp >= translation_table + 123 )
  263.         tp = translation_table;
  264. }
  265. -----------------------------------------------------------------------------
  266. \bug5.c
  267. \bug5.c(26) : error C2446: '=' : no conversion from 'struct ::address_element_type __near *__near * ' to 'const struct ::address_element_type __near *__near * '
  268. \bug5.c(36) : error C2446: '>=' : no conversion from 'struct ::address_element_type __near *__near * ' to 'const struct ::address_element_type __near *__near * '
  269. \bug5.c(37) : error C2446: '=' : no conversion from 'struct ::address_element_type __near *__near * ' to 'const struct ::address_element_type __near *__near * '
  270.  
  271. There should be no problem implicitely coercing a pointer to a constant
  272. pointer. The above should not be errors.
  273.  
  274. *****************************************************************************
  275. BUG6
  276. *****************************************************************************
  277. typedef int sort_fn_ptr_type( const void *, const void * );
  278.  
  279. static int
  280. compare_row( const void *a, const void *b )
  281. {
  282.     return *((int *) a) - *((int *) b);
  283. }
  284.  
  285. static int
  286. compare_col( const void *a, const void *b )
  287. {
  288.     return *((int *) b) - *((int *) a);
  289. }
  290.  
  291. void 
  292. func_ok1(int i)
  293. {    
  294.     sort_fn_ptr_type *fn = i == 1 ? (sort_fn_ptr_type *) compare_col
  295.                   : (sort_fn_ptr_type *) compare_row;
  296. }
  297.  
  298. void 
  299. func_ok2()
  300. {    
  301.     sort_fn_ptr_type *fn = compare_row;
  302. }
  303.  
  304. void
  305. func_broken(int i)
  306. {    
  307.     sort_fn_ptr_type *fn = i == 1 ? compare_col : compare_row;
  308. }
  309. -----------------------------------------------------------------------------
  310. \bug6.c
  311. \bug6.c(31) : fatal error C1001: INTERNAL COMPILER ERROR
  312.         (compiler file 'msc1.cpp', line 555)
  313.         Contact Microsoft Product Support Services
  314.  
  315. Only explicit coerction fix the internal compiler error.
  316.  
  317. *****************************************************************************
  318. BUG7
  319. *****************************************************************************
  320. const int TRUE = 1;
  321.  
  322. int dummy( int i );
  323.  
  324. int bug( int crv )
  325. {
  326.     while ( TRUE )
  327.     {
  328.     if ( dummy( crv ) )
  329.     {
  330.         crv = dummy( crv );
  331.     }
  332.     else
  333.     {
  334.         return crv;
  335.     }
  336.     }
  337. }
  338. -----------------------------------------------------------------------------
  339. \bug7.c
  340. \bug7.c(18) : error C2202: 'bug' : not all control paths return a value
  341.  
  342. This is clearly not true. In fact, changing to definition of TRUE to
  343.  
  344. #define TRUE 1
  345.  
  346. "fix" the problem. Apparently const is not considered constant...
  347.  
  348. *****************************************************************************
  349. BUG8
  350. *****************************************************************************
  351. /* #define const */
  352.  
  353. class buggy_obj
  354. {
  355.     int *edge1_[4];
  356.     int *edge2_[4];
  357.  
  358. public:
  359.     const int * const *edge1() const;
  360.     const int * const *edge2() const;
  361. };
  362.  
  363. const int * const *
  364. buggy_obj::edge1( ) const 
  365. {
  366.     return (const int * const *) edge1_;
  367. }
  368.  
  369. const int * const *
  370. buggy_obj::edge2( ) const 
  371. {
  372.     return edge2_;
  373. }
  374. -----------------------------------------------------------------------------
  375. bug8.c
  376. bug8.c(22) : error C2553: no legal conversion of return value to return type 'const int __near *const __near * '
  377.  
  378. Again const problems... '#define const' "fix" the problem.
  379. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  380. Elber Gershon                            gershon@cs.utah.edu
  381. Computer Science Department              Fax: (801) 581-5843
  382. University of Utah 84112                 Tel: (801) 585-5635
  383.