[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#160978: libstdc++5-dev: constness problem with std::set



Package: libstdc++5-dev
Version: 1:3.2.1-0pre1
Severity: normal

The following fragment generates an error for me:

======================================================================
#include <set>


template <class T>
class AutoPtr
{
public:
  T* getObjectPtr () { return 0; }
  const T* getObjectPtr () const { return 0; }
};


class WrappedClass
{
};


class TestClass
{
private:
  typedef std::set<AutoPtr<WrappedClass> > WrappedClassList;
  WrappedClassList _objects;

public:
  void testMethod () {
    for (WrappedClassList::iterator i=_objects.begin (); i!=_objects.end (); ++i)
      WrappedClass* C = (*i).getObjectPtr ();
  }
};
======================================================================

when compiled with:  g++-3.2 test.cpp

test.cpp: In member function `void TestClass::testMethod()':
test.cpp:27: invalid conversion from `const WrappedClass*' to `WrappedClass*'

I cannot work out if the bug is caused by my installing the debian
packages on woody rather than unstable.  However, the fragment
compiles correctly if std::vector is used in place of std::set.

If the "const T* getObjectPtr () const { return 0; }" line is removed,
it gives the following:

test.cpp: In member function `void TestClass::testMethod()':
test.cpp:26: passing `const AutoPtr<WrappedClass>' as `this' argument of `T*
   AutoPtr<T>::getObjectPtr() [with T = WrappedClass]' discards qualifiers


Regards,
Matt


-- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux xanadu 2.4.20pre7int #1 SMP Sat Sep 14 09:47:58 BST 2002 i686
Locale: LANG=C, LC_CTYPE=

Versions of packages libstdc++5-dev depends on:
ii  g++-3.2                    1:3.2.1-0pre1 The GNU C++ compiler.
ii  gcc-3.2-base               1:3.2.1-0pre1 The GNU Compiler Collection (base
ii  libc6-dev                  2.2.5-14.2    GNU C Library: Development Librari
ii  libstdc++5                 1:3.2.1-0pre1 The GNU stdc++ library version 3



Reply to: