public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libstdc++/6886: bit vector iterator uses wrong 1 constant
@ 2002-05-31  6:25 meissner
  0 siblings, 0 replies; 2+ messages in thread
From: meissner @ 2002-05-31  6:25 UTC (permalink / raw)
  To: gcc-gnats; +Cc: gcc-patches


>Number:         6886
>Category:       libstdc++
>Synopsis:       bit vector iterator uses wrong 1 constant
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 31 05:16:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Marcus Meissner <meissner@suse.de>
>Release:        3.1 20020410 (prerelease)
>Organization:
SuSE Linux AG
>Environment:
System: Linux gershwin 2.4.18-SMP #1 SMP Mon May 13 09:48:57 UTC 2002 x86_64 unknown
Architecture: x86_64

host: x86_64-unknown-linux-gnu
build: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-gnu
configured with: /home/hammer/gcc/configure --prefix=/usr --host=x86_64-unknown-linux --build=x86_64-unknown-linux --libdir=/usr/lib64 --enable-languages=c,c++ --enable-threads=posix --disable-nls
>Description:


The stl bitvector implementation contains in both the iterator and
const_iterator implementation the code:

  reference operator*() const { return reference(_M_p, 1U << _M_offset); }

Since the bit_type is an unsigned long, it should be 1UL here.

I have attached a testcase exhibiting the problem and a fix in 
the Fix section.

Ciao, Marcus

>How-To-Repeat:

#include <assert.h>
#include <vector>

typedef std::vector<bool> bvec;

int
main() {
	int	i, num = 0;

	bvec v;

	v.resize(66);

	for (i = 0 ; i < 66 ; i++)
		v[i] = 0;

	v[1]	= 1;
	v[33]	= 1;
	v[49]	= 1;
	v[65]	= 1;

	for (bvec::iterator j = v.begin() ; j < v.end() ; j++) {
		if (bool(*j)) num++;
	}
	assert (num == 4);
	return 0;
}

>Fix:

--- libstdc++-v3/include/bits/stl_bvector.h.long	Fri May 31 11:35:24 2002
+++ libstdc++-v3/include/bits/stl_bvector.h	Fri May 31 11:35:36 2002
@@ -166,7 +166,7 @@
   _Bit_iterator(_Bit_type * __x, unsigned int __y) 
     : _Bit_iterator_base(__x, __y) {}
 
-  reference operator*() const { return reference(_M_p, 1U << _M_offset); }
+  reference operator*() const { return reference(_M_p, 1UL << _M_offset); }
   iterator& operator++() {
     _M_bump_up();
     return *this;
@@ -223,7 +223,7 @@
     : _Bit_iterator_base(__x._M_p, __x._M_offset) {}
 
   const_reference operator*() const {
-    return _Bit_reference(_M_p, 1U << _M_offset);
+    return _Bit_reference(_M_p, 1UL << _M_offset);
   }
   const_iterator& operator++() {
     _M_bump_up();
>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: libstdc++/6886: bit vector iterator uses wrong 1 constant
@ 2002-05-31 17:58 pme
  0 siblings, 0 replies; 2+ messages in thread
From: pme @ 2002-05-31 17:58 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, meissner, nobody, pme

Synopsis: bit vector iterator uses wrong 1 constant

Responsible-Changed-From-To: unassigned->pme
Responsible-Changed-By: pme
Responsible-Changed-When: Fri May 31 17:37:28 2002
Responsible-Changed-Why:
    I changed it.
State-Changed-From-To: open->closed
State-Changed-By: pme
State-Changed-When: Fri May 31 17:37:28 2002
State-Changed-Why:
    I've applied the patch for 3.1.1 and 3.2.
    
    This of course won't be detectable on systems where
    unsigned and unsigned long are the same size, which
    is why it's gone undetected so long.  The testcase
    you gave has been added to the v3 testsuite.
    
    Thanks.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6886


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

end of thread, other threads:[~2002-06-01  0:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-31  6:25 libstdc++/6886: bit vector iterator uses wrong 1 constant meissner
2002-05-31 17:58 pme

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