Bug 29187 - Comparison with Pointer to Template Function Requires Explicit Cast
Summary: Comparison with Pointer to Template Function Requires Explicit Cast
Status: RESOLVED DUPLICATE of bug 11407
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-22 22:19 UTC by Justin Piper
Modified: 2006-09-22 23:33 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Piper 2006-09-22 22:19:01 UTC
When I try to compile the code below, g++ reports "error: assuming cast to type 'bool (*)(evaluator&)' from overloaded function" on the line indicated. I have isolated the comparison to the pointer to the template function "stop" as the source of the problem. Is this the correct behavior?

   #include <iostream>

   struct evaluator { bool (*eval)(evaluator&); };

   template <typename T>
   bool stop(T &e) { return true; }

   bool eval(evaluator &e) { return true; }

   int main() {
      typedef bool (*evalf)(evaluator&);
      struct evaluator e = { stop<evaluator> };

      // error: assuming cast to type 'bool (*)(evaluator&)' from
      // overloaded function
      std::cout << (e.eval == stop<evaluator>) << '\n';

      // ok--eval is not templated
      std::cout << (e.eval == eval) << '\n';

      // ok--explicitly cast to correct type
      std::cout << (e.eval == static_cast<evalf>(stop<evaluator>)) << '\n';

      return 0;
   }

I compiled this using the MinGW port of g++ 3.4.2 on W2kSP4. I unfortunately do not have easy access to g++ 4.1.1, however Kai-Uwe Bux reports the same result from that version via comp.lang.c++ (discussion archived at http://groups.google.com/group/comp.lang.c++/browse_frm/thread/b25fee316ec891b6).
Comment 1 Andrew Pinski 2006-09-22 23:33:56 UTC
There was a defect report about this problem to the C++ standard.

Anyways this is a dup of bug 11407.  The C++ standard committee decided this was valid thing to do.

*** This bug has been marked as a duplicate of 11407 ***