public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24702]  New: Koenig found functoid ref, but "cannot be used as a function"
@ 2005-11-07  7:09 pierhyth at gmail dot com
  2005-11-07 13:37 ` [Bug c++/24702] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: pierhyth at gmail dot com @ 2005-11-07  7:09 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2662 bytes --]

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:

testit.cc: In function ‘int main()’:
testit.cc:26: error: ‘dummyx::dummyFunct’ cannot be used as a function
testit.cc:28: 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
                    function"
           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


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


^ permalink raw reply	[flat|nested] 11+ messages in thread
[parent not found: <bug-24702-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2013-09-06  7:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-07  7:09 [Bug c++/24702] New: Koenig found functoid ref, but "cannot be used as a function" pierhyth at gmail dot com
2005-11-07 13:37 ` [Bug c++/24702] " pinskia at gcc dot gnu dot org
2005-11-09  1:33 ` pierhyth at gmail dot com
2005-11-16 19:28 ` gdr at integrable-solutions dot net
2005-12-04  5:09 ` gdr at gcc dot gnu dot org
     [not found] <bug-24702-4@http.gcc.gnu.org/bugzilla/>
2013-09-05 14:29 ` paolo.carlini at oracle dot com
2013-09-05 14:40 ` redi at gcc dot gnu.org
2013-09-05 14:43 ` redi at gcc dot gnu.org
2013-09-05 15:18 ` paolo.carlini at oracle dot com
2013-09-06  1:19 ` pierhyth at gmail dot com
2013-09-06  7:30 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).