Re: GCC 4.1.0 compile error

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

 



On 3/16/07, Pranabesh Dash <pranabesh.dash@xxxxxxxxx> wrote:

Hi,
The following piece of code compiles fine with 3.4.2, 4.0.0 but errors out on 4.1.0. Seems like a GCC bug. The friend function name is recognized if called as a function but does not work when used as a function pointer. An explicit function declaration (or definition reordered) is needed to get it to compile with 4.1.0.

Do you believe this is a bug or a feature???

--P.D

#include <iostream>

using namespace std;

class object;
typedef void (func_ptr)( object* );
class object {

  public:
      object() {}
      ~object() {}

    void top_func();
    void call_func_ptr(func_ptr);
  protected:
    friend void frnd_func(object*);

  private:
     int member;
};

//friend.cpp: In member function #void object::top_func()#:
//friend.cpp:27: error: #frnd_func# was not declared in this scope
// The following needs to be uncommented to get 4.1.0 to compile
//void frnd_func(object*) ;

void object::top_func() {
  frnd_func(this); // Does not complain on this
  call_func_ptr(frnd_func); // But complains on this !!!!!
}

void object::call_func_ptr(func_ptr fp) {
   fp(this);
}

void frnd_func(object* obj) {
  obj->member = 4;
}

main () {

   object my_obj;
}


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux