[gnu.g++.lib.bug] AVector Bug?

gordon%stats.ucl.ac.uk@NSFNET-RELAY.AC.UK (Gordon Joly) (06/12/89)

I have had some problems with a class generated by ``genclass double
ref AVec''; I have been able to use the files double.AVec.h etc, but
my small test program below gives worse results! For example I have
seen line 23 work correctly. I am sure that I am slightly off the
track, but also feel that the generated classes are a little bit off
as well.

Gordon Joly.

libg++ 1.35.0 on SUN-3/160; g++ 1.35.1- with gcc 1.35 using gas 1.34, 

karl:/stats/staff/karl/gordon/BAIES/ws[34] cat -n marginal.cc 
     1	// 
     2	// marginal.cc
     3	//
     4	
     5	#include "double.AVec.h"
     6	
     7	doubleAVec data(4,0.0);
     8	
     9	class jtnode
    10	{
    11	  doubleAVec marginals();
    12	  //   doubleAVec marginals(4,1.0); gives an error
    13	  doubleAVec cpt();
    14	 public:
    15	  jtnode(int size);
    16	  void jtfunction();
    17	  void insert(doubleAVec );
    18	};
    19	
    20	void
    21	jtnode::jtfunction()
    22	{
    23	  marginals = cpt + cpt + cpt ;
    24	  marginals = cpt * 3;
    25	  marginals = cpt + 10;
    26	}
    27	
    28	void
    29	jtnode::insert(doubleAVec d)
    30	{
    31	  cpt = d ;
    32	}
    33	
    34	main()
    35	{
    36	  jtnode a(4);
    37	  a.insert(data);
    38	}
    39	
    40	// end of marginal.cc
    41	
    42	
    43	   
    44	      
karl:/stats/staff/karl/gordon/BAIES/ws[35] !g
g++ -v -c marginal.cc
g++ version 1.35.1-
 /stats/staff/karl/lib/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 marginal.cc /tmp/cca04916.cpp
GNU CPP version 1.35
 /stats/staff/karl/lib/gcc-cc1plus /tmp/cca04916.cpp -quiet -dumpbase marginal.cc -noreg -version -o /tmp/cca04916.s
GNU C++ version 1.35.1- (68k, MIT syntax) compiled by GNU C version 1.35.
double.Vec.h:169: parse error before `doubleVec_error_handler'
double.Vec.h:169: warning: data definition lacks type or storage class
double.Vec.h:172: parse error before `set_doubleVec_error_handler'
double.Vec.h:172: `one_arg_error_handler_t' undeclared, outside of functions
double.Vec.h:172: parse error before `f'
double.Vec.h:172: warning: data definition lacks type or storage class
In method void jtnode::jtfunction ():
marginal.cc:23: invalid operands to binary +
marginal.cc:24: invalid operands to binary *
marginal.cc:25: invalid lvalue in assignment
In method void jtnode::insert (struct doubleAVec):
marginal.cc:31: invalid lvalue in assignment
karl:/stats/staff/karl/gordon/BAIES/ws[36] 



karl:/stats/staff/karl/gordon/BAIES/ws[37] cat double.AVec.h
// This may look like C code, but it is really -*- C++ -*-
/* 
Copyright (C) 1988 Free Software Foundation
    written by Doug Lea (dl@rocky.oswego.edu)

This file is part of GNU CC.

GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.  No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing.  Refer to the GNU CC General Public
License for full details.

Everyone is granted permission to copy, modify and redistribute
GNU CC, but only under the conditions described in the
GNU CC General Public License.   A copy of this license is
supposed to have been given to you along with GNU CC so you
can know your rights and responsibilities.  It should be in a
file named COPYING.  Among other things, the copyright notice
and this notice must be preserved on all copies.  
*/


#ifndef _doubleAVec_h
#pragma once
#define _doubleAVec_h 1

#include "double.Vec.h"

class doubleAVec : public doubleVec
{
protected:
  void                  check_len(int l);
  double*                  vec();
                        doubleAVec(int l, double* d);
  public:
                        doubleAVec ();
                        doubleAVec (int l);
                        doubleAVec (int l, double& fill_value);
                        doubleAVec (doubleAVec&);
                        ~doubleAVec ();

  doubleAVec&              operator =  (doubleAVec& a);
  doubleAVec&              operator =  (double& fill_value);

// vector by scalar -> vector operations

  friend doubleAVec        operator +  (doubleAVec& a, double& b);
  friend doubleAVec        operator -  (doubleAVec& a, double& b);
  friend doubleAVec        operator *  (doubleAVec& a, double& b);
  friend doubleAVec        operator /  (doubleAVec& a, double& b);

  doubleAVec&              operator += (double& b);
  doubleAVec&              operator -= (double& b);
  doubleAVec&              operator *= (double& b);
  doubleAVec&              operator /= (double& b);

// vector by vector -> vector operations

  friend doubleAVec        operator +  (doubleAVec& a, doubleAVec& b);
  friend doubleAVec        operator -  (doubleAVec& a, doubleAVec& b);
  doubleAVec&              operator += (doubleAVec& b);
  doubleAVec&              operator -= (doubleAVec& b);

  doubleAVec               operator - ();

  friend doubleAVec        product(doubleAVec& a, doubleAVec& b);
  doubleAVec&              product(doubleAVec& b);
  friend doubleAVec        quotient(doubleAVec& a, doubleAVec& b);
  doubleAVec&              quotient(doubleAVec& b);

// vector -> scalar operations

  friend double            operator * (doubleAVec& a, doubleAVec& b);

  double                   sum();
  double                   min();
  double                   max();
  double                   sumsq();

// indexing

  int                   min_index();
  int                   max_index();

// redundant but necesssary
  friend doubleAVec        concat(doubleAVec& a, doubleAVec& b);
  friend doubleAVec        map(doubleMapper f, doubleAVec& a);
  friend doubleAVec        merge(doubleAVec& a, doubleAVec& b, doubleComparator f);
  friend doubleAVec        combine(doubleCombiner f, doubleAVec& a, doubleAVec& b);
  friend doubleAVec        reverse(doubleAVec& a);
  doubleAVec               at(int from = 0, int n = -1);
};


inline doubleAVec::doubleAVec() {}
inline doubleAVec::doubleAVec(int l) :(l) {}
inline doubleAVec::doubleAVec(int l, double& fill_value) : (l, fill_value) {}
inline doubleAVec::doubleAVec(doubleAVec& v) :(v) {}
inline doubleAVec::~doubleAVec() {}


inline double* doubleAVec::vec()
{
  return s;
}

inline doubleAVec::doubleAVec(int l, double* d)
{
  len = l;
  s = d;
}

inline void doubleAVec::check_len(int l)
{
  if (l != len)
    error("nonconformant vectors.");
}


#endif
karl:/stats/staff/karl/gordon/BAIES/ws[38]