🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #852

g++-2.2.2

#852
From: how
Date: Fri, 21 Aug 1992 09:57
261 lines
6665 bytes
You probably already know about this, but here it is anyway:

Machine: Sun Sparcstation 2,  SunOS 4.1.1
Compiler: gcc 2.2.2  built locally according to the vanilla directions.
          [I did the stage3 comparision stuff also]
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/specs
gcc version 2.2.2

configure command: I forget.
No local modifications to compiler source.

Synopsis:

The following code from groff-1.05 fails to compile using gcc-2.2.2

from lib/errarg.h

class errarg {
  enum { EMPTY, STRING, CHAR, INTEGER, DOUBLE } type;
  union {
    const char *s;
    int n;
    char c;
    double d;
  };
 public:
  errarg();
  errarg(const char *);
  errarg(char);
  errarg(unsigned char);
  errarg(int);
  errarg(double);
  int empty() const;
  void print() const;
};

from lib/errarg.c


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

errarg::errarg(const char *p) : s(p == 0 ? "(null)" : p), type(STRING)
{
}

g++ errarg.c yields

errarg.c: In method `errarg::errarg (const char *)':
errarg.c:26: assignment between incompatible pointer types

Message is from line 5532 of cp-typeck.c.

Source Files

------------------------errarg.h--------------------------------------
// -*- C++ -*-
/* Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
     Written by James Clark (jjc@jclark.uucp)

This file is part of groff.

groff is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any later
version.

groff is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with groff; see the file LICENSE.  If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */

class errarg {
  enum { EMPTY, STRING, CHAR, INTEGER, DOUBLE } type;
  union {
    const char *s;
    int n;
    char c;
    double d;
  };
 public:
  errarg();
  errarg(const char *);
  errarg(char);
  errarg(unsigned char);
  errarg(int);
  errarg(double);
  int empty() const;
  void print() const;
};

extern errarg empty_errarg;

extern void errprint(const char *,
		     const errarg &arg1 = empty_errarg,
		     const errarg &arg2 = empty_errarg,
		     const errarg &arg3 = empty_errarg);

------------------------------errarg.c-----------------------------------
// -*- C++ -*-
/* Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
     Written by James Clark (jjc@jclark.uucp)

This file is part of groff.

groff is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any later
version.

groff is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with groff; see the file LICENSE.  If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */

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

errarg::errarg(const char *p) : s(p == 0 ? "(null)" : p), type(STRING)
{
}

errarg::errarg() : type(EMPTY)
{
}

errarg::errarg(unsigned char cc) : type(CHAR)
{
  c = cc;
}

errarg::errarg(int nn) : type(INTEGER), n(nn)
{
}

errarg::errarg(char cc) : type(CHAR), c(cc)
{
}

errarg::errarg(double dd) : type(DOUBLE), d(dd)
{
}

int errarg::empty() const
{
  return type == EMPTY;
}

extern "C" {
  const char *itoa(int);
}
	    
void errarg::print() const
{
  switch (type) {
  case INTEGER:
    fputs(itoa(n), stderr);
    break;
  case CHAR:
    putc(c, stderr);
    break;
  case STRING:
    fputs(s, stderr);
    break;
  case DOUBLE:
    fprintf(stderr, "%g", d);
    break;
  case EMPTY:
    break;
  }
}

errarg empty_errarg;

void errprint(const char *format, 
	      const errarg &arg1,
	      const errarg &arg2,
	      const errarg &arg3)
{
  assert(format != 0);
  char c;
  while ((c = *format++) != '\0') {
    if (c == '%') {
      c = *format++;
      switch(c) {
      case '%':
	fputc('%', stderr);
	break;
      case '1':
	assert(!arg1.empty());
	arg1.print();
	break;
      case '2':
	assert(!arg2.empty());
	arg2.print();
	break;
      case '3':
	assert(!arg3.empty());
	arg3.print();
	break;
      default:
	assert(0);
      }
    }
    else
      putc(c, stderr);
  }
}
----------------------------------------assert.h------------------------
// -*- C++ -*-
/* Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
     Written by James Clark (jjc@jclark.uucp)

This file is part of groff.

groff is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any later
version.

groff is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with groff; see the file LICENSE.  If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */

#ifndef ASSERT_H
#define ASSERT_H
#ifdef __GNUG__
volatile
#endif
void assertion_failed(int, const char *);

inline void do_assert(int expr, int line, const char *file)
{
  if (!expr)
    assertion_failed(line, file);
}
#endif /* ASSERT_H */

#undef assert

#ifdef NDEBUG
#define assert(ignore) /* as nothing */
#else
#define assert(expr) do_assert(expr, __LINE__, __FILE__)
#endif
--------------------------the-end-----------------------------------
Technical Details
Message-ID: <9208210421.AA06481@relay2.UU.NET>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!milhow1.UUCP!how

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!milhow1.UUCP!how
From: how@milhow1.UUCP
Subject: g++-2.2.2
Message-ID: <9208210421.AA06481@relay2.UU.NET>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 21 Aug 1992 09:57:42 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 263