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

2005-11-06 Thread pierhyth at gmail dot com
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 

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) = "

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

2005-11-08 Thread pierhyth at gmail dot com


--- Comment #2 from pierhyth at gmail dot com  2005-11-09 01:33 ---
The current C++ standard says that Koenig applies "when an unqualified 
name is used as the postfix-expression in a function call" which from
what I've read, must include the case of functoids/functors and references
to functoids/functors.

It is true that some people seem to be arguing that the standard be changed
to restrict Koenig to only functions, a view which seems to me rather
unfortunate.  However the fact remains that the current standard allows
functors and the g++ compiler complies with this by allowing functors.
The issue is that references to functors appear to be broken in the most
recent versions of g++.

I have written much code that relies on g++ finding references to functors
through Koenig lookup.  This code compiled fine with version 3.2.  The
problem only arose when I tried to update to the 4.0 compiler.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24702



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

2013-09-05 Thread pierhyth at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24702

--- Comment #9 from Mark Phillips  ---
Thanks Jonathan for the information on the updated standard and the rationale
behind restricting Koenig to actual functions and function templates.

In one way it is a bit of a pity - it does make functors second-class citizens
compared to functions - but the linked document explains some additional
considerations, namely the risk of over-visibility of names.  Perhaps it is a
reasonable choice for now.  Hopefully a better solution will be introduced down
the track (maybe extending it to functors, while at the same time
narrowing/allowing-control-over namespaces to be looked up).