[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::axp-developer

Title:Alpha Developer Support
Notice:[email protected], 800-332-4786
Moderator:HYDRA::SYSTEM
Created:Mon Jun 06 1994
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3722
Total number of notes:11359

3400.0. "Cogit Corporation" by HYDRA::LNARAYAN () Tue Mar 25 1997 19:52

    Company Name :  Cogit Corporation
    Contact Name :  John Wood
    Phone        :  415.908.1910
    Fax          :  
    Email        :  [email protected]
    Date/Time in :  25-MAR-1997 19:51:39
    Entered by   :  L. Narayan
    SPE center   :  MRO

    Category     :  UNIX
    OS Version   :  V4.0B
    System H/W   :  8400 5/350


    Brief Description of Problem:
    -----------------------------

From:	SMTP%"[email protected]" 25-MAR-1997 12:27:04.31
To:	[email protected]
CC:	[email protected]
Subj:	porting/C++ problems

Return-Path: [email protected]
Received: by asimov.mro.dec.com (UCX V4.1-12, OpenVMS V6.2 VAX);
	Tue, 25 Mar 1997 12:27:02 -0500
Received: from pobox1.pa.dec.com by fluid.mro.dec.com (5.65v4.0/1.1.8.2/19Nov96-0448PM)
	id AA07667; Tue, 25 Mar 1997 12:27:15 -0500
Received: by pobox1.pa.dec.com; id AA16622; Tue, 25 Mar 97 09:27:15 -0800
Received: from ns.pilot.net by mail1.digital.com (5.65 EXP 4/12/95 for V3.2/1.0/WV)
	id AA27303; Tue, 25 Mar 1997 09:22:49 -0800
Received: from cogit.com (unknown-79-101.ergosum.com [206.189.79.101]) by mail.pilot.net with SMTP id JAA09905 for <[email protected]>; Tue, 25 Mar 1997 09:22:49 -0800 (PST)
Received: from reficio.cogit.com by cogit.com (SMI-8.6/SMI-SVR4)
	id JAA07815; Tue, 25 Mar 1997 09:22:33 -0800
From: [email protected] (John Wood)
Received: by reficio.cogit.com (SMI-8.6/client-1.3)
	id JAA11809; Tue, 25 Mar 1997 09:22:32 -0800
Date: Tue, 25 Mar 1997 09:22:32 -0800
Message-Id: <[email protected]>
To: [email protected]
Subject: porting/C++ problems
Cc: [email protected]
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Md5: HihH6G3WKJD13LiRYtpA5g==

I'm not sure that this is the proper channel for these issues; if it's not, please let me know and I will forward the following to the Customer Support Center.  We are 
using C++ 5.5 and Digital UNIX 4.0b on a 8400 5/350.

Cogit Corp customer id: 951755
Program account code: 210970


Digital C++ Bugs and Peculiarities
=====================================

BUGS
----

1)  Compiler may optimize-out side effects of a statement when a
    templatized type has an empty destructor!!

    EXAMPLE from List<T>

    while (size) {		// destroy each element of the array
       array[--size].~T();
    }

    Produces an infinite loop if T is int:

   
    WORKAROUND:

    Make templatized destructor call side-effect free:

    while (size) {		// destroy each element of the array
      --size;
       array[size].~T();
    }


2) templates parameter names must match exactly

   EXAMPLE:
	template <class KEY, class VALUE>
	class Hash {
	public:
	  Hash( const KEY& k, const VALUE& v);
	};

	template <class K, class V>
	Hash<K,V>::Hash( const K& k, const V& v) {
	}

	
    averto.cogit.com:185% cxx Temp.cc
	cxx: Error: Temp.cc, line 8: Missing ")".
	Hash<K,V>::Hash( const K& k, const V& v) {
	------------------------^

    Changing "KEY" to "K" solves the problem.

    WORKAROUND:
	Use consistent names for template parameters everywhere.

3)  Inheritance of certain functions doesn't seem to work.  (this
    needs furtheer characterization!)

    EXAMPLE:
#include <stdio.h>
#include <assert.h>

struct foo {
  foo(int y) : x(y) {};
  int x;
};

class FooPtr_Base {
public:
  
#ifdef BUG  
  int operator!() const { return p == 0; }
#endif
  
  ~FooPtr_Base() { printf( "destructor called\n"); delete p; }
  FooPtr_Base() : p(0) {}
  foo* p;
};

class FooPtr : public FooPtr_Base {
public:

#ifndef BUG  
  int operator!() const { return p == 0; }
#endif
  
  FooPtr(foo* pf) {
    p = pf;
  }
  
  FooPtr(const FooPtr& src){
    p = src.p;
    printf("copy constructor called\n");
    (foo* &)src.p = 0;
  }
};

extern FooPtr f( FooPtr b );

int main (int , char **argv) {
  FooPtr l5(new foo(2));
  FooPtr q( f(l5 ));
  
  assert(!l5);
  return 0;
}

averto.cogit.com:886% sh -x inhb
+ cxx -UBUG -w0 -g -nocleanup -O0 -inline none InheritanceBug.cc -o InheritanceBug 
+ InheritanceBug 
copy constructor called
destructor called
destructor called
destructor called
+ cxx -DBUG -w0 -g -nocleanup -O0 -inline none InheritanceBug.cc -o InheritanceBug 
+ InheritanceBug 
Assertion failed: !l5, file InheritanceBug.cc, line 45


	WORKAROUND:
	In this case, moving operator= down a level solves the problem.
	Unfortunately, we don't know why this happens, so the cure is
	magic and may not be a general remedy.  The above example was
	derived from SafePtr<T> (tSafePtr originally demonstrated the
	problem).

4)  -O0 doesn't seem to turn off all optimzation.

    EXAMPLE:
	#include <stdio.h>
        #include <assert.h>
	
	class XXXX {
	public:
	  XXXX() { x = 0; }
	  XXXX( const XXXX& );
	  XXXX& operator = (const XXXX&);
	  int x;
	};
	
	inline
	XXXX::XXXX( const XXXX& y) {
	  printf("Copy called\n");
	  x = y.x+1;
	}
	
	inline
	XXXX& XXXX::operator=( const XXXX& y) {
	  printf("Assignment called\n");
	  x = y.x;
	  return *this;
	}
	
	XXXX f ( XXXX a, XXXX b, XXXX c) {
	  b = c;
	  a = b;
	  return a;
	}
	
	int main() {
	  XXXX x1, x2, x3;
	
	  XXXX y = f(x1,x2,x3) ;
	  assert(x1.x == 0);
	  assert(x2.x == 0);
	  // assert(x3.x == 0);
	  return y.x - 2;
	}
	
    The copy constructor/destructor calls for x3 are optimized out even
    when -O0 is on the command line.  This lead us down a wild goose chase
    looking for bug #3.

    WORKAROUND:
	?????

5) templates must be in header files, along with any classes or
   definitions that template relies on.

   EXAMPLE:

	template <class T>
	class XXX {
	public:
	  static XXX<T> * & root();
	};

	template <class T> XXX<T> * &
	XXX<T>::root()
	{
	    static XXX<T> *the_root = 0;
	    return( the_root );
	}

	int 
	main()
	{
	    XXX<int>** y = &XXX<int>::root();
	    assert( &XXX<int>::root() == y );
	    assert( (void *)&XXX<double>::root() != (void *)y );
	}


    Does not link:

	cxx -g3 -nocleanup -L../lib -L/proj/cogit/build/mainline/digital-gnu/\
	lib -o t-platform t-platform.o 
	cxx: Error: ./cxx_repository/XXX__Td.cxx, line 4: Invalid declaration.
	typedef XXX<double > __dummy_;
	-----------^
	cxx: Error: ./cxx_repository/XXX__Ti.cxx, line 4: Invalid declaration.
	typedef XXX<int > __dummy_;
	-----------^
	ld:
	Unresolved:
	XXX<int>::root(void)
	XXX<double>::root(void)
	make: *** [t-platform] Error 1

    Moving the template declarations into a header solves the problem.

    WORKAROUND:
	All template class (and function?) definitions must be in headers.
        Or use some unfortunate combination of options (like
        -tlocal).

==========================


Again, please let me know if these issues are not appropriate to send to alpha-developer and I will send them 
elsewhere.

I appreciate your attention to these matters and welcome any solutions you may be able to provide.

John Wood
Manager, Discovery Center Operations
Cogit Corporation
415.908.1910
T.RTitleUserPersonal
Name
DateLines
3400.1expecting example codeHYDRA::LNARAYANMon Apr 14 1997 14:04109
From:	HYDRA::LNARAYAN     "R Lakshminarayan, Software Partner Engg" 14-APR-1997 12:57:03.27
To:	US4RMC::"[email protected]"
CC:	LNARAYAN
Subj:	 porting/C++ problems

John Wood

Thanks for contacting Alpha developer support. As you said this is the
right place to report Partner porting issues. I have few answers, But
need example code. Our C++ team wants to know whether you would be 
interested in becoming field test site to field test C++ Version 6.0? 
(starting this summer) Please note that the reference number for this 
call is #3400 dated 25-MAR-1997 and quote this number when communicating
wrt to this call.

Thank You
-Nari
Alpha Developer Support

Answers from our C++ group for your questions:

item 1)

>    while (size) {		// destroy each element of the array
>       array[--size].~T();
>    }
>
>    Produces an infinite loop if T is int:

If the size is a negative number, then it shall run into loop.
However, you also mentioned that the following workaround:

>    while (size) {		// destroy each element of the array
>      --size;
>       array[size].~T();
>    }

It more likely a bug somewhere then.
We would like to look into this case, please provide us a small test that
could demonstrate this loop problem.
--------------------------------------------------------------------------------
>2) templates parameter names must match exactly

The workaround is as stated.  This is fixed in V6.0.

--------------------------------------------------------------------------------
item 3)

>+ cxx -DBUG -w0 -g -nocleanup -O0 -inline none InheritanceBug.cc -o
>InheritanceBug 
>+ InheritanceBug 
>Assertion failed: !l5, file InheritanceBug.cc, line 45
>
>
>	WORKAROUND:
>	In this case, moving operator= down a level solves the problem.
>	Unfortunately, we don't know why this happens, so the cure is
>	magic and may not be a general remedy.  The above example was
>	derived from SafePtr<T> (tSafePtr originally demonstrated the
>	problem).

I could not reproduce the same problem from your source posted at item 3)
on both compiler: 
	DEC C++ V5.5-004 on Digital UNIX (Alpha)
	DEC CXX X5.6-130 on Digital UNIX (Alpha)

shijun.zko.dec.com> cxx -DBUG -w0 -g -nocleanup -O0 -inline none cpp3531c.cxx
ld:
Unresolved:
f(FooPtr)
shijun.zko.dec.com> $CEXE/deccxx_driver -DBUG -w0 -g -nocleanup -O0 -inline none
cpp3531c.cxx
ld:
Unresolved:
f(FooPtr)

After I provided the definition to the "f(FooPtr)" as {return b;},
the code ran fine from both compilers.
shijun.zko.dec.com> a.out
copy constructor called
copy constructor called
destructor called
destructor called
destructor called

Please provide us a test that can show this problem.
--------------------------------------------------------------------------------
>4)  -O0 doesn't seem to turn off all optimzation.
>
>    The copy constructor/destructor calls for x3 are optimized out even
>    when -O0 is on the command line.  This lead us down a wild goose chase
>    looking for bug #3.

This was done to provide a consistent semantic meaning with and without
optimization.  I've noted a suggestion to provide a way to disable
optimization of copy ctor/dtor calls.
--------------------------------------------------------------------------------
>5) templates must be in header files, along with any classes or
>   definitions that template relies on.
>
The workaround is as stated.  Yes, this is a documented restriction of the
automatic instantiation implementation for V5.n.  We plan to lift this
restriction in V6.0.
--------------------------------------------------------------------------------




    
3400.2example code...HYDRA::LNARAYANMon Apr 14 1997 18:38158
From:	US6RMC::"[email protected]" "John Wood" 14-APR-1997 17:05:04.43
To:	hydra::lnarayan
CC:	
Subj:	porting/C++ problems/ call #3400


reference call #3400 dated 25 MAR 1997

> 
> >    while (size) {		// destroy each element of the array
> >       array[--size].~T();
> >    }
> >
> >    Produces an infinite loop if T is int:
> 
> If the size is a negative number, then it shall run into loop.

Obviously, but size is not a negative number.  This code works on all
other compilers we use.  

>            please provide us a small test that could demonstrate
> this loop problem.

Happy to:

#include <stdio.h>
#include <new.h>
#include <assert.h>

template <class T>
class List {
    int max_size;
    int size;
    T   *array;  
public:

    int length() { return( size ); }
    T &elem( int i ) { assert( i < size ); return( array[i] ); }
    void *operator new( size_t, void *place ) { return( place ); }

    void append( const T &x ) {
        assert( size < max_size );
        new (& array[size]) T( x ); 
        ++size;
    }

    List() : max_size( 8 ), size( 0 )  { 
        array = (T *) new char[sizeof( T ) * max_size];
    }

    ~List() {
        while( size > 0 ) 
            array[--size].~T();
    }
};

int
main()
{
    printf( "List start\n" );
    {
        List<int> li;
        int i;
        for( i = 0; i < 4; ++i )
            li.append( i * i );
        for( i = 0; i < 4; ++i )
            printf( "%d => %d\n", i, li.elem( i ) );
    }
    printf( "List end\n" );
}
        
> item 3)
> 
> >+ cxx -DBUG -w0 -g -nocleanup -O0 -inline none InheritanceBug.cc -o
> After I provided the definition to the "f(FooPtr)" as {return b;},
> the code ran fine from both compilers.

Try: { return new foo(0); }

#include <stdio.h>
#include <assert.h>

struct foo {
  foo(int y) : x(y) {};
  int x;
};

class FooPtr_Base {
public:
  
#ifdef BUG  
  int operator!() const { return p == 0; }
#endif
  
  ~FooPtr_Base() { printf( "destructor called\n"); delete p; }
  FooPtr_Base() : p(0) {}
  foo* p;
};

class FooPtr : public FooPtr_Base {
public:

#ifndef BUG  
  int operator!() const { return p == 0; }
#endif
  
  FooPtr(foo* pf) {
    p = pf;
  }
  
  FooPtr(const FooPtr& src){
    p = src.p;
    printf("copy constructor called\n");
    (foo* &)src.p = 0;
  }
};

extern FooPtr f( FooPtr b );

int main (int , char **argv) {
  FooPtr l5(new foo(2));
  FooPtr q( f(l5 ));
  
  assert(!l5);
  return 0;
}


FooPtr 
f( FooPtr b )
{
    return new foo(0);
}



___

Regards,

John Wood

% ====== Internet headers and postmarks (see DECWRL::GATEWAY.DOC) ======
% Received: from mail13.digital.com by us6rmc.mro.dec.com (5.65/rmc-17Jan97) id AA00611; Mon, 14 Apr 97 16:58:52 -0400
% Received: from mail-oak-1.pilot.net by mail13.digital.com (8.7.5/UNX 1.5/1.0/WV) id QAA02058; Mon, 14 Apr 1997 16:54:02 -0400 (EDT)
% Received: from cogit.com (unknown-79-101.ergosum.com [206.189.79.101]) by mail-oak-1.pilot.net with SMTP id NAA18068 for <[email protected]>; Mon, 14 Apr 1997 13:48:22 -0700 (PDT)
% Received: from reficio.cogit.com by cogit.com (SMI-8.6/SMI-SVR4) id MAA20059; Mon, 14 Apr 1997 12:34:49 -0700
% From: [email protected] (John Wood)
% Received: by reficio.cogit.com (SMI-8.6/client-1.3) id MAA01431; Mon, 14 Apr 1997 12:36:09 -0700
% Date: Mon, 14 Apr 1997 12:36:09 -0700
% Message-Id: <[email protected]>
% Subject: porting/C++ problems/ call #3400
% To: hydra::lnarayan
% Mime-Version: 1.0
% Content-Type: text/plain; charset=us-ascii
% Content-Transfer-Encoding: 7bit
% Content-Md5: jn08D0IzBZwSyURbuaw+Xw==
    
3400.3this is a bugHYDRA::LNARAYANTue Apr 15 1997 11:472
    The problem reported in the previous mail is a bug and C++ notes conf
    confirms this. see note 3531 in c++ for more info.
3400.4closedHYDRA::LNARAYANTue Apr 15 1997 12:0326
From:	DECC::KAO "Shi-Jung Kao  15-Apr-1997 1058 -0500" 15-APR-1997 11:00:32.72
To:	HYDRA::LNARAYAN
CC:	
Subj:	Item 3 has been fixed in V5.6 C++ field test release, and will be available soon.

        <<< TURRIS::DISK$NOTES_PACK:[NOTES$LIBRARY]C_PLUS_PLUS.NOTE;2 >>>
                                    -< C++ >-
================================================================================
Note 3531.7                     C++ questions...                          7 of 7
DECC::KAO                                            12 lines  15-APR-1997 10:58
                     -< Problem item 3 has been fixed... >-
--------------------------------------------------------------------------------
Thanks for your tests.
Since August already noted the problem into the bug tracking system,
I just want to clarify the following:

Your workaround on item 1, the loop problem is correct.

Item 3:

>Assertion failed: !l5, file InheritanceBug.cc, line 45

This problem has been fixed in our next release of DEC C++ V5.6
compiler.  Its field test release for UNIX will be available in a week or so.