public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18053] New: __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A
@ 2004-10-19  7:43 j at zsch dot de
  2004-10-19 11:29 ` [Bug libstdc++/18053] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: j at zsch dot de @ 2004-10-19  7:43 UTC (permalink / raw)
  To: gcc-bugs

struct A 
{
    // ...
    B* operator&();
    operator B() const;
};

__gnu_cxx::hash_set<A> stores values of B, the return type of operator&(). It 
should store values of A as the similar hash_map<A,bool> does.

The following example shows the effect. hash_set doesn't use copy constructor 
of A, instead it calls A::operator int(). When retrieving values, the iterator 
pretends to deliver A, but in real it delivers int. A::print() doesn't print 
the values _a2=1000 and 2000.

Nevertheless hash_set::value_type seems to be A (not int).



#include <ext/hash_set>
#include <ext/hash_map>
#include <iostream>

using namespace std;
using namespace __gnu_cxx;

#define WITH_SET_ERROR



struct A
{
    A( int a, int a2 )
    : 
        _a(a)
        , _a2(a2)    
    { 
        cout << "A(" << _a << ")\n"; 
    }


    A( const A& a )
    : 
        _a(a._a), 
        _a2(a._a2) 
    { 
        cout << "A(" << _a << ") copy\n"; 
    }


    ~A()
    { 
        cout << "~A(" << _a << ")\n"; 
    }



    void print() const
    { 
        cout << _a << "," << _a2; 
    }


    bool operator==( const A& a ) const
    { 
        return _a == a._a  &&  _a2 == a._a2; 
    }


#ifdef WITH_SET_ERROR
    int* operator&()
    { 
        cout << "operator &() " << _a << "\n"; return &_a; 
    }
#endif

    operator int() const
    { 
        cout << "operator int() " << _a << "\n"; 
        return _a; 
    }


    int _a;
    int _a2;
};


namespace __gnu_cxx
{
    template<>
    struct hash< A >
    {
        size_t operator() ( const A& a ) const  { return a._a; }
    };
}



int main( int, char** )
{
    A a ( 1, 1000 );
    A b ( 2, 2000 );

    cout << "a="; a.print(); cout << "\n";
    cout << "b="; b.print(); cout << "\n";
  
    {
        cout << "\nset:\n";
        typedef hash_set<A> Set;
        Set set;
        set.insert( a );
        set.insert( b );

        for( Set::iterator it = set.begin(); it != set.end(); it++ )
        {
            it->print();  cout << "\n";
        }
    }

    {
        cout << "\nmap:\n";  // hash_map is ok
        typedef hash_map<A,bool> Map;
        Map map;
        map[ a ] = true;
        map[ b ] = true;

        for( Map::iterator it = map.begin(); it != map.end(); it++ )
        {
            it->first.print();  cout << "\n";
        }
    }

    cout << "\n";
}

-- 
           Summary: __gnu_cxx::hash_set<A> uses return type of
                    A::operator&() instead of A
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: j at zsch dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug libstdc++/18053] __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A
  2004-10-19  7:43 [Bug c++/18053] New: __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A j at zsch dot de
@ 2004-10-19 11:29 ` pinskia at gcc dot gnu dot org
  2004-10-19 12:08 ` pcarlini at suse dot de
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-19 11:29 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |libstdc++


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


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

* [Bug libstdc++/18053] __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A
  2004-10-19  7:43 [Bug c++/18053] New: __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A j at zsch dot de
  2004-10-19 11:29 ` [Bug libstdc++/18053] " pinskia at gcc dot gnu dot org
@ 2004-10-19 12:08 ` pcarlini at suse dot de
  2004-11-01 23:25 ` bkoz at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pcarlini at suse dot de @ 2004-10-19 12:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2004-10-19 12:08 -------
More about this issue later, only two quick remarks:
1- Current mainline doesn't even compile the testcase, due to type mismatches
in the allocator caused by the overloaded operators.
2- In any case, it's unlikely that more-than-trivial changes will go in for the
hash_* extensions, since we are in the process of adding the new unordered
containers in "tr1", which will provide similar functionalities in a portable
way. For more info see, f.i., N1687 in:

  http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/

-- 


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


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

* [Bug libstdc++/18053] __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A
  2004-10-19  7:43 [Bug c++/18053] New: __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A j at zsch dot de
  2004-10-19 11:29 ` [Bug libstdc++/18053] " pinskia at gcc dot gnu dot org
  2004-10-19 12:08 ` pcarlini at suse dot de
@ 2004-11-01 23:25 ` bkoz at gcc dot gnu dot org
  2004-11-01 23:27 ` bkoz at gcc dot gnu dot org
  2005-01-22  9:16 ` pcarlini at suse dot de
  4 siblings, 0 replies; 6+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2004-11-01 23:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bkoz at gcc dot gnu dot org  2004-11-01 23:25 -------
Created an attachment (id=7455)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7455&action=view)
testcase


corrected test case, set/hash_set/map/hash_map.

-- 


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


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

* [Bug libstdc++/18053] __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A
  2004-10-19  7:43 [Bug c++/18053] New: __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A j at zsch dot de
                   ` (2 preceding siblings ...)
  2004-11-01 23:25 ` bkoz at gcc dot gnu dot org
@ 2004-11-01 23:27 ` bkoz at gcc dot gnu dot org
  2005-01-22  9:16 ` pcarlini at suse dot de
  4 siblings, 0 replies; 6+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2004-11-01 23:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bkoz at gcc dot gnu dot org  2004-11-01 23:27 -------

I think this is INVALID. I've attached a corrected test case for
set/map/hash_set/hash_map.

-benjamin

-- 


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


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

* [Bug libstdc++/18053] __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A
  2004-10-19  7:43 [Bug c++/18053] New: __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A j at zsch dot de
                   ` (3 preceding siblings ...)
  2004-11-01 23:27 ` bkoz at gcc dot gnu dot org
@ 2005-01-22  9:16 ` pcarlini at suse dot de
  4 siblings, 0 replies; 6+ messages in thread
From: pcarlini at suse dot de @ 2005-01-22  9:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2005-01-22 09:16 -------
Ok..

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


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


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

end of thread, other threads:[~2005-01-22  9:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-19  7:43 [Bug c++/18053] New: __gnu_cxx::hash_set<A> uses return type of A::operator&() instead of A j at zsch dot de
2004-10-19 11:29 ` [Bug libstdc++/18053] " pinskia at gcc dot gnu dot org
2004-10-19 12:08 ` pcarlini at suse dot de
2004-11-01 23:25 ` bkoz at gcc dot gnu dot org
2004-11-01 23:27 ` bkoz at gcc dot gnu dot org
2005-01-22  9:16 ` pcarlini at suse dot de

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