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++/29618] New: argument dependent lookup: what about built-in types?


  Consider the following piece of C++ code:

- --------------------------------
#include <boost/functional/hash.hpp>
#include <cstddef>

struct A {
    int n;

size_t hash_value(A v)
    return boost::hash_value(v.n);

size_t hash_value(long long int v)
    size_t seed = 0;
    boost::hash_combine(seed, static_cast<long int>(v & 0xffff));
    boost::hash_combine(seed, static_cast<long int>(v >> 32));
    return seed;

template<class T>
size_t calc_hash(T v)
    size_t seed = 0;
    boost::hash_combine(seed, v);
    return seed;

template size_t calc_hash(A);
template size_t calc_hash(long long int);
- --------------------------------

  Now, calc_hash() for some type simply calls hash_combine() for it, which will
internally resolve to calling hash_value() for the type (I can provide a
minimal version with no dependence on the Boost include files if someone thinks
that's a problem). So the compiler needs to find the proper definition of
hash_value() for that type.

  Earlier versions of g++ (say, 3.2 which I have handy here) didn't quite
conform to the standard, so the way to make the above code work was to declare
the above hash_value() functions inside the boost namespace. But these days g++
has ADL, which means that hash_value() instead has to be declared in the same
namespace as the type. In the code I'm posting above, this works fine for A;
even if I move it inside some namespace, as long as I also move hash_value(A)
inside the same namespace, the code will compile.

  But what about long long int? When I try to compile the above with g++ 4.1, I

error: call of overloaded 'hash_value(const long long int&)' is ambiguous

followed by a list of candidate functions, which includes all the ones declared
in the header file, but not the one declared in this file. Again, in g++ 3.2
this compiles as long as hash_value(long long) is declared inside the boost
namespace too. But with 4.1 I can't seem to be able to make it compile at all.
So is this a bug, or am I doing something wrong here?


           Summary: argument dependent lookup: what about built-in types?
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: v dot vasaitis at sms dot ed dot ac dot uk

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