This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/24702] New: Koenig found functoid ref, but "cannot be used as a function"

The problem relates to functoid objects ("function like" objects, ie
ones 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.

Here is an example:

#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


When I try to compile this code using g++ version 4.0.2 I get the
following errors: In function ?int main()?: error: ?dummyx::dummyFunct? cannot be used as a function error: ?dummyx::mymyDummyFunct? cannot be used as a function

I see no reason why such references should not be able to be used
as a function.  As you see, if it is explicitly namespace-qualified
it can be.  And according to Koenig rules, the unqualified name should
indeed be found and, as operator() is applicable for the found reference,
it should be usable as a function.  Indeed, this is what version 3.2.3
of g++ does.

The above test code compiles fine with g++ version 3.2.3.  The errors
seem only to occur in versions 3.4 and later (certainly they occur for 
versions 3.4.5 and 4.0.2.)

Additional version information:

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

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

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

           Summary: Koenig found functoid ref, but "cannot be used as a
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pierhyth at gmail dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]