egcs bug (internal compiler error 9)

Andy Glew glew@cs.wisc.edu
Tue Oct 20 12:04:00 GMT 1998


Pursuant to the error message attached below,
I am reporting the following internal compiler error:

******** the compilation, with error message ********************
cd ~/hack/options/
make
g++    -c options.cc 
options.cc: In function `class ostream & operator <<(class ostream &, const class option_base &)':
options.cc:20: warning: passing `const option_base' as `this' argument of `class ostream & option_base::put_to_stream(class ostream &)' discards const
options.cc: At top level:
options.cc:41: Internal compiler error 9.
options.cc:41: Please submit a full bug report to `egcs-bugs@cygnus.com'.
make: *** [options.o] Error 1

Compilation exited abnormally with code 2 at Tue Oct 20 14:02:17

******** the program options.cc *********************************
// $Header: /u/g/l/glew/hack/options/RCS/options.cc,v 1.3 1998/10/20 18:44:00 glew Exp glew $

#include <cstdio>
#include <iostream>
#include <stl.h>
#include <string>


class option_base {
public:
  string option_name;
  string option_message;
  bool value_set;		// 0 if not set, and should use default; 1 if set
  // the actual value and defaults are set in derived types
  virtual ostream& put_to_stream(ostream& s) = 0;
  friend ostream& operator<< ( ostream& s, const option_base& o) ;
};
ostream& operator<< ( ostream& s, const option_base& o) 
{
  return o.put_to_stream(s);
}


typedef map<string,option_base*> options_registry_t;
options_registry_t options_registry;

template<class T> class option : public option_base {
public:
  T* value_pointer;		// pointer to the actual option value;
				// poiter so that can be shared
  T* default_pointer;		// pointer to default value;
				// pointer so that default can be set after initialization
public:

  // Constructor family
  // many combinations of default values - more than C++'s default syntax can indicate

  // Full constructor
  friend void option_constructor<T>(
				    T* value_pointer, T* default_pointer, 
				    string option_name, string option_message );
  option( T* value_pointer, T* default_pointer, string option_name, string option_message="" ) 
    { option( value_pointer, default_pointer, option_name, option_message ; };


  // 
  virtual ostream& put_to_stream(ostream& s) { return s << *this; };
  friend ostream& operator<< <T> ( ostream& s, const option<T>& o);
};


template<class T> ostream& operator<<( ostream& s, const option<T>& o)
{
  s << "{\n";
#define print_it(field)  s << #field " = "<< o.field << "\n";
  print_it(option_name);
  print_it(value_set);
  print_it(value_pointer);
  if( o.value_pointer ) { s << "*value_pointer" " = " << *(o.value_pointer) << "\n"; }
  print_it(default_pointer);
  if( o.default_pointer ) { s << "*default_pointer" " = " << *(o.default_pointer) << "\n"; }
  print_it(option_message);
  s << "}\n";

  return s;
}



template<class T> option_constructor<T>::option(
						T* value_pointer,
						T* default_pointer, 
						string option_name, 
						string option_message 
						)
{
  this->value_set = 0;
  this->value_pointer = ( value_pointer ? value_pointer : new T );
  this->default_pointer = ( default_pointer ? default_pointer : new T );
  this->option_name = option_name;
  this->option_message = option_message;
  options_registry[option_name] = this;
}



float f = 6.7;

option<int> switch1((int*)0,(int*)0,"switch1","this is a sample message for switch1");
option<int> switch2((int*)0,(int*)0,"switch2","this is a sample message for switch2");
option<float> switchF((float*)0,&f,"switchF","this is a sample message for switch2");



void
main(int argc, char** argv)
{
  for( options_registry_t::const_iterator o = options_registry.begin(); 
       o != options_registry.end();
       o++ )
    {
      o->second->put_to_stream(cout);
    }
}


---

Andy Glew, glew@cs.wisc.edu

[Place URGENT in email subject line for mail filter prioritization.]



More information about the Gcc-bugs mailing list