home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.win32
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!hellgate.utah.edu!irit.cs.utah.edu!gershon
- From: gershon%irit.cs.utah.edu@cs.utah.edu (Elber Gershon)
- Subject: NT October release C++ bugs
- Date: 14 Dec 92 16:05:58 MST
- Message-ID: <1992Dec14.160558.7685@hellgate.utah.edu>
- Organization: University of Utah CS Dept
- Lines: 373
-
- Below are several bugs in the C++ of the beta october release of window NT.
- I would appreciate if someone can upload this to Compuserve as Microsoft
- requests since I have no such access.
-
- All small programs below fail on the NT C++ compiler but
- succeed using unix AT&T 2.1/3.0 C++ as well as Sun and SGI C++ compiler.
- All these small examples were extracted from a very large C++ project that
- runs under unix for several years. All compiled in NT using 'cl -c -Tp file.c'.
-
- thanks
-
- Gershon Elber
-
- *****************************************************************************
- BUG1
- *****************************************************************************
- #include <stdio.h> /* Standard I/O always available. */
-
- struct point_type;
-
- typedef point_type vector_type;
- typedef point_type line_type;
- typedef point_type p2pt_type;
-
- class point_type
- {
- double xyz_[3];
- public:
-
- public:
- point_type();
- point_type( double px, double py, double pz );
- inline double &x();
- inline double x() const;
- inline double &y();
- inline double y() const;
- inline double &z();
- inline double z() const;
-
- /* Remove this constructore and this file will not fail with
- * INTERNAL COMPILER ERROR
- */
- point_type( const point_type *p );
- };
-
-
- extern line_type *
- line_thru_2pts( const point_type *pt1,
- const point_type *pt2,
- line_type *res = NULL );
-
-
- void
- compute_visib_bound()
- {
- int i;
- line_type l;
-
- for ( i = 0; i < 10; i++ )
- {
- point_type pt1, pt2;
- point_type pt = point_type( 1, 2, 3 );
-
- if ( pt.x() > pt.y() )
- {
- pt1 = point_type( ( pt.z() + pt.y() ) / -pt.x(), 1.0, 0.0 );
- pt2 = point_type( ( pt.z() - pt.y() ) / -pt.x(), -1.0, 0.0 );
- }
- else
- {
- pt1 = point_type( 1.0, ( pt.z() + pt.x() ) / -pt.y(), 0.0 );
- pt2 = point_type( -1.0, ( pt.z() - pt.x() ) / -pt.y(), 0.0 );
- }
- l = line_thru_2pts( &pt1, &pt2 );
- }
- }
- -----------------------------------------------------------------------------
- 'cl /c /Tp bug.c' dies:
-
- bug.c
- bug.c(58) : error C2102: '&' requires lvalue
- bug.c(58) : fatal error C1001: INTERNAL COMPILER ERROR
- (compiler file 'msc1.cpp', line 555)
- Contact Microsoft Product Support Services
-
-
- The constructor 'point_type( const point_type *p );' is implicitly used
- in the assignment of 'l = line_thru_2pts( &pt1, &pt2 );' and these are the
- lines that causes it to die.
- This program was successfully compiled using unix AT&T C++.
-
- *****************************************************************************
- BUG2
- *****************************************************************************
- #include <stdio.h>
-
- class point_type
- {
- public:
- double xyz[3];
- point_type( double px, double py, double pz );
- };
-
- typedef point_type vector_type;
-
- main()
- {
- vector_type v = vector_type( 1, 2, 3 );
-
- printf( "%lf %lf %lf\n", v.xyz[0], v.xyz[1], v.xyz[2] );
- }
- -----------------------------------------------------------------------------
- 'cl /c /Tp bug.c' fails with the following:
- bug.c
- bug.c(14) : error C2514: 'vector_type' : class has no constructors
- bug.c(14) : error C2512: 'point_type' : no appropriate default constructor available
- bug.c(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed
-
- By typedef'ing vector_type should be identical to point_type.
- This program was successfully compiled using unix AT&T C++.
-
- *****************************************************************************
- BUG3
- *****************************************************************************
- #include <stdio.h>
-
- class point_type
- {
- double xyz_[3];
- public:
-
- public:
- point_type();
- point_type( double px, double py, double pz );
- point_type( const point_type *p );
- };
-
- class plane_equation_type
- {
- double abcd_[4];
- public:
-
- public:
- plane_equation_type() {};
- plane_equation_type( double a, double b, double c, double d );
- plane_equation_type( const plane_equation_type *p ); // asserted constructor.
- };
-
- extern point_type
- pt_from_3_planes( const plane_equation_type plane1,
- const plane_equation_type plane2,
- const plane_equation_type plane3 );
-
- void
- offset_pt_normals()
- {
- plane_equation_type planes[3];
- point_type p = pt_from_3_planes( &planes[0], &planes[1], &planes[2] );
- }
- -----------------------------------------------------------------------------
- 'cl /c /Tp b3.c' dies on this program with:
-
- b3.c
- Compiler error (assertion): file @(#)typer.c:1.114, line 192 source=34
- Compiler error (assertion): file @(#)typer.c:1.114, line 161 source=34
- Compiler error (assertion): file @(#)typer.c:1.114, line 192 source=34
- Compiler error (assertion): file @(#)typer.c:1.114, line 192 source=34
- Compiler error (assertion): file @(#)typer.c:1.114, line 161 source=34
- Compiler error (assertion): file @(#)typer.c:1.114, line 192 source=34
- b3.c(34) : fatal error C1003: error count exceeds 5; stopping compilation
-
- Again, related to the 'plane_equation_type( const plane_equation_type *p );'
- constructor from pointer to the object.
-
- *****************************************************************************
- BUG4
- *****************************************************************************
- enum domain_span_enum
- {
- DOMAIN_SPAN_NONE = 0x00,
- DOMAIN_SPAN_START = 0x01,
- DOMAIN_SPAN_END = 0x02,
- DOMAIN_SPAN_ALL = 0x03
- };
-
- class point_type
- {
- double xyz_[3];
- public:
-
- public:
- point_type();
- point_type( double px, double py, double pz );
- set_attr( char *nm, int in );
- set_attr( char *nm, double in );
- set_attr( char *nm, char *in );
- };
-
- void
- bug4()
- {
- point_type pt = point_type( 1, 2, 3 );
-
- pt.set_attr( "bug", DOMAIN_SPAN_NONE );
- }
- -----------------------------------------------------------------------------
- 'cl /c /Tp bug4.c' quits with the following message:
-
- bug4.c
- bug4.c(27) : error C2668: 'set_attr' : ambiguous call to overloaded function
-
- The overloaded set_attr function has a match with an integer the enum
- should be automatically coerced to.
-
- *****************************************************************************
- BUG5
- *****************************************************************************
- #include <stdio.h>
- struct address_element_type
-
- {
- void *addr;
- void *trans;
- };
-
- class shared_objects_type : public address_element_type
- {
- address_element_type **translation_table;
-
- public:
- void add_translation( void *key,
- const address_element_type *ent );
- const address_element_type **tmember( void *key ) const;
- };
-
- void
- shared_objects_type::add_translation( void *key,
- const address_element_type *ent )
- {
- const address_element_type **tp;
-
- /* Get a pointer to the hash point. */
- tp = translation_table + ((unsigned int)key >> 5);
-
- /* Perform a linear search for free slots or the target address. */
- for ( int i = 0; i < 120; i++ )
- /* Grab the first free address. */
- if ( *tp == NULL )
- {
- *tp = ent;
- return;
- }
- else if ( ++tp >= translation_table + 123 )
- tp = translation_table;
- }
- -----------------------------------------------------------------------------
- \bug5.c
- \bug5.c(26) : error C2446: '=' : no conversion from 'struct ::address_element_type __near *__near * ' to 'const struct ::address_element_type __near *__near * '
- \bug5.c(36) : error C2446: '>=' : no conversion from 'struct ::address_element_type __near *__near * ' to 'const struct ::address_element_type __near *__near * '
- \bug5.c(37) : error C2446: '=' : no conversion from 'struct ::address_element_type __near *__near * ' to 'const struct ::address_element_type __near *__near * '
-
- There should be no problem implicitely coercing a pointer to a constant
- pointer. The above should not be errors.
-
- *****************************************************************************
- BUG6
- *****************************************************************************
- typedef int sort_fn_ptr_type( const void *, const void * );
-
- static int
- compare_row( const void *a, const void *b )
- {
- return *((int *) a) - *((int *) b);
- }
-
- static int
- compare_col( const void *a, const void *b )
- {
- return *((int *) b) - *((int *) a);
- }
-
- void
- func_ok1(int i)
- {
- sort_fn_ptr_type *fn = i == 1 ? (sort_fn_ptr_type *) compare_col
- : (sort_fn_ptr_type *) compare_row;
- }
-
- void
- func_ok2()
- {
- sort_fn_ptr_type *fn = compare_row;
- }
-
- void
- func_broken(int i)
- {
- sort_fn_ptr_type *fn = i == 1 ? compare_col : compare_row;
- }
- -----------------------------------------------------------------------------
- \bug6.c
- \bug6.c(31) : fatal error C1001: INTERNAL COMPILER ERROR
- (compiler file 'msc1.cpp', line 555)
- Contact Microsoft Product Support Services
-
- Only explicit coerction fix the internal compiler error.
-
- *****************************************************************************
- BUG7
- *****************************************************************************
- const int TRUE = 1;
-
- int dummy( int i );
-
- int bug( int crv )
- {
- while ( TRUE )
- {
- if ( dummy( crv ) )
- {
- crv = dummy( crv );
- }
- else
- {
- return crv;
- }
- }
- }
- -----------------------------------------------------------------------------
- \bug7.c
- \bug7.c(18) : error C2202: 'bug' : not all control paths return a value
-
- This is clearly not true. In fact, changing to definition of TRUE to
-
- #define TRUE 1
-
- "fix" the problem. Apparently const is not considered constant...
-
- *****************************************************************************
- BUG8
- *****************************************************************************
- /* #define const */
-
- class buggy_obj
- {
- int *edge1_[4];
- int *edge2_[4];
-
- public:
- const int * const *edge1() const;
- const int * const *edge2() const;
- };
-
- const int * const *
- buggy_obj::edge1( ) const
- {
- return (const int * const *) edge1_;
- }
-
- const int * const *
- buggy_obj::edge2( ) const
- {
- return edge2_;
- }
- -----------------------------------------------------------------------------
- bug8.c
- bug8.c(22) : error C2553: no legal conversion of return value to return type 'const int __near *const __near * '
-
- Again const problems... '#define const' "fix" the problem.
- /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
- Elber Gershon gershon@cs.utah.edu
- Computer Science Department Fax: (801) 581-5843
- University of Utah 84112 Tel: (801) 585-5635
-