[Bug c++/42281] g++ instantiates function templates at the wrong place

2009-12-04 Thread pinskia at gcc dot gnu dot org


--- Comment #1 from pinskia at gcc dot gnu dot org  2009-12-04 19:56 ---
One issue is Koenig lookup does not apply to fundamental types.


-- 


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



[Bug c++/42281] g++ instantiates function templates at the wrong place

2009-12-04 Thread jezz at hkfree dot org


--- Comment #2 from jezz at hkfree dot org  2009-12-04 21:30 ---
I have tried to simplify the code, but I have created only problem with int
(not with user structure). In real code we have also something like this:

Tested with same compilers:
template2.cc: In function #8216;bool isEqual(const A, const B) [with A =
std::mapint, int, B = std::mapint, double]#8217;:
template2.cc:16:4:   instantiated from #8216;void isTrue(const A, const B)
[with A = std::mapint, int, B = std::mapint, double]#8217;
template2.cc:53:17:   instantiated from here
template2.cc:6:17: error: no match for #8216;operator==#8217; in #8216;aA ==
aB#8217;


[Code]
#include map

template typename A, typename B
bool isEqual(A const aA, B const aB)
   {
   return aA == aB;
   }

// Forward declaration works
//template typename Key, typename Value1, typename Value2
//bool isEqual(std::mapKey,Value1 const aA, std::mapKey,Value2 const aB);

template typename A, typename B
inline void isTrue(A const aA, B const aB)
   {
   if (not isEqual(aA, aB)) throw new std::exception();
   }

template typename A, typename B
void isFalse(A const aA, B const aB)
   {
   if (isEqual(aA, aB)) throw new std::exception();
   }

template typename Key, typename Value1, typename Value2
bool isEqual(std::mapKey,Value1 const aA, std::mapKey,Value2 const aB)
   {
   if (aA.size() != aB.size()) return false;
   for (typename std::mapKey,Value1::const_iterator it1 = aA.begin();
 it1 != aA.end(); ++it1)
  {
  typename std::mapKey,Value2::const_iterator it2 = aB.find(it1-first);
  if (it2 == aB.end() or it1-second != it2-second) return false;
  }
   return true;
   }

int
main(int argc, char *argv[])
   {
   isTrue(1, 1);

   double da, db;
   da = 1.0;
   db = 2.0;
   isFalse(da, db);

   isTrue(da, 1);

   std::mapint, int ma;
   std::mapint, double mb;

   isTrue(ma, mb); // Error here

   return 0;
   }
[/Code]


-- 


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



[Bug c++/42281] g++ instantiates function templates at the wrong place

2009-12-04 Thread pinskia at gcc dot gnu dot org


--- Comment #3 from pinskia at gcc dot gnu dot org  2009-12-04 22:34 ---
(In reply to comment #2)
 I have tried to simplify the code, but I have created only problem with int
 (not with user structure). In real code we have also something like this:

Your original code is invalid code as Koenig lookup is not able to find the
function for std::mapKey,Value1 as the associated namespace is only std and
not the global namespace.


-- 


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



[Bug c++/42281] g++ instantiates function templates at the wrong place

2009-12-04 Thread pinskia at gcc dot gnu dot org


--- Comment #4 from pinskia at gcc dot gnu dot org  2009-12-05 00:13 ---
The reduced testcase in comment #0 is really PR 29131 which talks about
fundemantal types.

And report's original code is invalid based on the associated namespace is std
there.

So closing as a dup of bug 29131.

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


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


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