bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with gcc 2.7.2.1


From: Gabriel
Subject: Problems with gcc 2.7.2.1
Date: Mon, 25 Dec 2000 16:08:20 +0800

Here is two problems:

1) Template support problem
2) Compiler internal error report


Here is descriptions in details:


1) Template support problem:

Template instantiation should be memeber -based not type(class)-based.
The following code works well in other compiler and run no error but is
disallowed by gcc:

Report:
02.cpp: In method `void Wrapper<Base>::do_action()':
02.cpp:15: no member function `Base::send()' defined

Codes:
     1  class Base {
     2  public:
     3     virtual ~Base() {}
     4  };
     5
     6  class Base1 {
     7  public:
     8     virtual ~Base1() {}
     9     virtual void send() {}
    10  };
    11
    12  template<typename T>
    13  class Wrapper {
    14  public:
    15     void do_action() {b.send();}
    16
    17  private:
    18     T b;
    19  };
    20
    21  int main(int argc, char *argv[]) {
    22     Wrapper<Base> b_w;
    23     //b_w.do_action();
    24
    25     return 0;
    26  }


2) Compile internal error:

Report:
03.cpp: In function `int main(int, char **)':
03.cpp:67: Internal compiler error 5.


Codes:
     1  #include <stdlib.h>
     2  #include <iostream.h>
     3  #include <algorithm>
     4  #include <list>
     5  #include <vector>
     6
     7  class Object {
     8  public:
     9     Object():val(rand() %50) {
    10        cout << "Object: " << val << " constructor call" << endl;
    11     }
    12
    13     // Copy constructor
    14     //
    15     Object(const Object &obj): val(obj.val) {
    16        cout << "Object: " << val << " copy constructor call" << endl;
    17     }
    18
    19     Object& operator = (const Object &obj) {
    20        this->val = obj.val;
    21        cout << "Object: " << val << " assign operator call" << endl;
    22        return *this;
    23     }
    24
    25     friend bool operator < (const Object &obj_l, const Object &obj_r) {
    26        return obj_l.val < obj_r.val;
    27     }
    28
    29     friend bool operator > (const Object &obj_l, const Object &obj_r) {
    30        return obj_l.val > obj_r.val;
    31     }
    32
    33     friend bool operator == (const Object &obj_l, const Object &obj_r) {
    34        return obj_l.val == obj_r.val;
    35     }
    36
    37     friend ostream& operator << (ostream &os, const Object &obj) {
    38        return os << obj.val;
    39     }
    40  private:
    41     int val;
    42  };
    43
    44  // Object factory
    45  //
-----------------------------------------------------------------------------
    46
    47  struct ObjGen {
    48     Object operator() () { return Object(); }
    49  };
    50
    51  // main function
    52  //
-----------------------------------------------------------------------------
    53
    54  int main( int argc, char *argv[]) {
    55    long size = 1000;
    56    vector<Object> obj_list;
    57
    58    obj_list.reserve(10);
    59
    60    if (argc==2) {
    61       size = atol(argv[1]);
    62    }
    63    clock_t ticks =clock();
    64    //generate_n(back_inserter(obj_list),size, ObjGen());
    65
    66    for (int i= 0; i<size; i++)
    67       obj_list.push_back(ObjGen()());
    68
    69    cout << "list: " << clock()-ticks << endl;
    70
    71    return 0;
    72  }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]