bug-gplusplus
[Top][All Lists]
Advanced

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

Reference to functoid error: "cannot be used as a function"


From: Dr Mark H Phillips
Subject: Reference to functoid error: "cannot be used as a function"
Date: Sat, 29 Oct 2005 13:01:57 +0930

Hi,

I'd like to report a g++ bug I've found.  I've attached three files
which illustrate the bug:

1. a simple program which illustrates the bug
2. the compiler output for this program
3. the output of g++ -E

The problem relates to functoid objects (objects with an operator()
defined) and references to them within a namespace.  When Koenig
lookup is used to find such a reference-to-functoid, g++ seems to
find it okay, but then states "cannot be used as a function".  If I
use an actual functoid object instead of a reference to one, it works
fine.  If I compile with g++ version 

  g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)

everything works fine.  It is only with recent versions like

  g++-3.4 (GCC) 3.4.5 20050809 (prerelease) (Ubuntu 3.4.4-6ubuntu8)

and

  g++-4.0 (GCC) 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)

where the bug occurs.

Cheers,

Mark Phillips.

#include <iostream>

namespace dummyx {

  struct Dummy {
    Dummy() {}
  };

  struct DummyFunct {
    int operator()(Dummy d) const {return 5;}
    static DummyFunct& full() {static DummyFunct f; return f;}
  };
  static DummyFunct& dummyFunct=DummyFunct::full();

  DummyFunct myDummyFunct;

  DummyFunct& mymyDummyFunct=myDummyFunct;

}

int main() {

  ::dummyx::Dummy const d;

  std::cout<<"dummyx::dummyFunct(d) = "<<dummyx::dummyFunct(d)<<std::endl;
  std::cout<<"dummyFunct(d) = "<<dummyFunct(d)<<std::endl; // fails with 3.4 
and 4.0
  std::cout<<"myDummyFunct(d) = "<<myDummyFunct(d)<<std::endl;
  std::cout<<"mymyDummyFunct(d) = "<<mymyDummyFunct(d)<<std::endl; // fails 
with 3.4 and 4.0

}

Attachment: testit.out.txt
Description: Text document

Attachment: testit.E.txt
Description: Text document


reply via email to

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