Anu
Anu

Reputation: 19

g++ 2.9-gnupro-98r2 ,error: Internal compiler error

I am facing a compilation error with one g++ version (2.9-gnupro-98r2)for LynxOS-178B 2.2.2, whereas the same code will be compiled without complaints with a newer version of g++, e.g. 4.3.3 for VxWorks 653 2.4.0.2.

The following example illustrates the problem:

int function_1(int)
{
  return 4;
}

double function_2(double)
{
  return 2;
}

typedef int (*fp1)(int);
typedef double (*fp2)(double);

struct A
{
  operator fp1()
  { 
    return function_1;                       // conversion function to pointer to function
  }

  operator fp2()
  {
    return function_2;                      // conversion function to pointer to function
  }

}a;

int call_to_class_object_1()
{
  double i = a(3.6);                       // calls function_2 via pointer returned from conversion function
  return i;
}

int call_to_class_object_2()
{
  int i = a(6);                            // calls function_1 via pointer returned from conversion function
  return i;
}

where I am calling double i = a(3.6); and int i = a(6); I am getting error

For 2.9-gnupro-98r2 I am getting:

../../src/Overloading_13_3_1_1_2_Call_to_object_of_class_type.cpp(30) : error: Internal compiler error.
../../src/Overloading_13_3_1_1_2_Call_to_object_of_class_type.cpp(30) : error: Please submit a Problem Report to Lynx Technical Support ([email protected]).
make[1]: *** [Overloading_13_3_1_1_2_Call_to_object_of_class_type.o] Error 1

If one compiler version accepts the code it cannot be completely wrong. My guess is that it conforms to the C++ standard, but the older compiler was lacking a proper implementation of the same.

  1. What exactly is the problem?
  2. Is there a portable way of writing that kind of code such that as much compilers as possible accept it?

Upvotes: 0

Views: 142

Answers (0)

Related Questions