public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29618]  New: argument dependent lookup: what about built-in types?
@ 2006-10-27 15:57 v dot vasaitis at sms dot ed dot ac dot uk
  2006-10-27 16:07 ` [Bug c++/29618] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: v dot vasaitis at sms dot ed dot ac dot uk @ 2006-10-27 15:57 UTC (permalink / raw)
  To: gcc-bugs

Hello,

  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
get:

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?

Thanks,
Vasilis


-- 
           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


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29618] argument dependent lookup: what about built-in types?
  2006-10-27 15:57 [Bug c++/29618] New: argument dependent lookup: what about built-in types? v dot vasaitis at sms dot ed dot ac dot uk
@ 2006-10-27 16:07 ` pinskia at gcc dot gnu dot org
  2006-10-27 22:47 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-27 16:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-10-27 16:07 -------
There is an open Defect report against the C++ standard about ADL and builtin
types.


-- 


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29618] argument dependent lookup: what about built-in types?
  2006-10-27 15:57 [Bug c++/29618] New: argument dependent lookup: what about built-in types? v dot vasaitis at sms dot ed dot ac dot uk
  2006-10-27 16:07 ` [Bug c++/29618] " pinskia at gcc dot gnu dot org
@ 2006-10-27 22:47 ` bangerth at dealii dot org
  2006-10-28  2:37 ` v dot vasaitis at sms dot ed dot ac dot uk
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2006-10-27 22:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bangerth at dealii dot org  2006-10-27 22:47 -------
Built-in types are not associated with any namespace. ADL therefore doesn't
apply to them -- name lookup proceeds from the present scope outward and
stops once a suitable name is found. This results in you getting all the
overloaded versions of the functions inside the boost namespace, because
this is the first namespace where the name is found. It never gets to the
global scope.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29618] argument dependent lookup: what about built-in types?
  2006-10-27 15:57 [Bug c++/29618] New: argument dependent lookup: what about built-in types? v dot vasaitis at sms dot ed dot ac dot uk
  2006-10-27 16:07 ` [Bug c++/29618] " pinskia at gcc dot gnu dot org
  2006-10-27 22:47 ` bangerth at dealii dot org
@ 2006-10-28  2:37 ` v dot vasaitis at sms dot ed dot ac dot uk
  2006-10-28  3:19 ` gdr at integrable-solutions dot net
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: v dot vasaitis at sms dot ed dot ac dot uk @ 2006-10-28  2:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from v dot vasaitis at sms dot ed dot ac dot uk  2006-10-28 02:37 -------
  Interesting analysis. However, wouldn't this imply that the example I posted
could be made to work if hash_value(long long) were put inside the boost
namespace? Because it doesn't really; and in fact I can't find any way to make
it work, and I'd be grateful if you could point one out to me.

  Which is the original purpose of this report I guess: Even if the standard
isn't really clear about how situations like this should be handled, it'd be
nice if g++ had at least one way to make them work, instead of none.

Thanks,
Vasilis


-- 

v dot vasaitis at sms dot ed dot ac dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29618] argument dependent lookup: what about built-in types?
  2006-10-27 15:57 [Bug c++/29618] New: argument dependent lookup: what about built-in types? v dot vasaitis at sms dot ed dot ac dot uk
                   ` (2 preceding siblings ...)
  2006-10-28  2:37 ` v dot vasaitis at sms dot ed dot ac dot uk
@ 2006-10-28  3:19 ` gdr at integrable-solutions dot net
  2006-10-28  3:56 ` pinskia at gcc dot gnu dot org
  2006-10-28 11:09 ` v dot vasaitis at sms dot ed dot ac dot uk
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at integrable-solutions dot net @ 2006-10-28  3:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from gdr at integrable-solutions dot net  2006-10-28 03:19 -------
Subject: Re:  argument dependent lookup: what about built-in types?

"v dot vasaitis at sms dot ed dot ac dot uk" <gcc-bugzilla@gcc.gnu.org> writes:

|   Interesting analysis. However, wouldn't this imply that the example I
posted
| could be made to work if hash_value(long long) were put inside the boost
| namespace?

I don't see why.

| Because it doesn't really; and in fact I can't find any way to make
| it work, and I'd be grateful if you could point one out to me.

the bugdatabase is about defects in the compiler suite, not about
asking help to fix your programs.  Please do not reopen bugs for the
sole purpose of  getting answers to questions that are best sent to
appropriate newgroups.

-- Gaby


-- 


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29618] argument dependent lookup: what about built-in types?
  2006-10-27 15:57 [Bug c++/29618] New: argument dependent lookup: what about built-in types? v dot vasaitis at sms dot ed dot ac dot uk
                   ` (3 preceding siblings ...)
  2006-10-28  3:19 ` gdr at integrable-solutions dot net
@ 2006-10-28  3:56 ` pinskia at gcc dot gnu dot org
  2006-10-28 11:09 ` v dot vasaitis at sms dot ed dot ac dot uk
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-28  3:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2006-10-28 03:56 -------
This is DR 225 against the C++ standard about ADL and fundamental types.
Here is what it says:
In discussing issue 197, the question arose as to whether the handling of
fundamental types in argument-dependent lookup is actually what is desired.
This question needs further discussion.


We already have a PR about that so this bug as invalid.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/29618] argument dependent lookup: what about built-in types?
  2006-10-27 15:57 [Bug c++/29618] New: argument dependent lookup: what about built-in types? v dot vasaitis at sms dot ed dot ac dot uk
                   ` (4 preceding siblings ...)
  2006-10-28  3:56 ` pinskia at gcc dot gnu dot org
@ 2006-10-28 11:09 ` v dot vasaitis at sms dot ed dot ac dot uk
  5 siblings, 0 replies; 7+ messages in thread
From: v dot vasaitis at sms dot ed dot ac dot uk @ 2006-10-28 11:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from v dot vasaitis at sms dot ed dot ac dot uk  2006-10-28 11:08 -------
  OK thanks, it's quite clear now. My apologies for acting inappropriately.

Regards,
Vasilis


-- 


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-10-28 11:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-27 15:57 [Bug c++/29618] New: argument dependent lookup: what about built-in types? v dot vasaitis at sms dot ed dot ac dot uk
2006-10-27 16:07 ` [Bug c++/29618] " pinskia at gcc dot gnu dot org
2006-10-27 22:47 ` bangerth at dealii dot org
2006-10-28  2:37 ` v dot vasaitis at sms dot ed dot ac dot uk
2006-10-28  3:19 ` gdr at integrable-solutions dot net
2006-10-28  3:56 ` pinskia at gcc dot gnu dot org
2006-10-28 11:09 ` v dot vasaitis at sms dot ed dot ac dot uk

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).