Bug 21244 - [4.0/4.1 Regression] Vector<bool> anonymous enum problem
Summary: [4.0/4.1 Regression] Vector<bool> anonymous enum problem
Status: VERIFIED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.1
Assignee: Paolo Carlini
URL:
Keywords:
: 24298 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-27 06:52 UTC by dominik.strasser
Modified: 2009-05-20 15:45 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-04-27 10:26:35


Attachments
Source file illustrating the faulty behavior (175 bytes, text/plain)
2005-04-27 06:54 UTC, dominik.strasser
Details
Another source illustrating the problem. (154 bytes, text/plain)
2005-04-27 06:55 UTC, dominik.strasser
Details
Use const static member instead of enum (255 bytes, patch)
2005-04-27 09:09 UTC, dominik.strasser
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description dominik.strasser 2005-04-27 06:52:22 UTC
The 2 source files illustrate how g++ 4.0.0 gets confused template
instantiation. It tries to instantiate an unrelated template.
Comment 1 dominik.strasser 2005-04-27 06:54:37 UTC
Created attachment 8747 [details]
Source file illustrating the faulty behavior

Error messages:
gcc4_template.C: In function &#8216;void foo()&#8217;:
gcc4_template.C:17: error: &#8216;Encoding::<anonymous enum>&#8217; is/uses
anonymous type
gcc4_template.C:17: error:   trying to instantiate &#8216;template<class T>
bool operator>(const Mpz&, T)&#8217;
Comment 2 dominik.strasser 2005-04-27 06:55:30 UTC
Created attachment 8748 [details]
Another source illustrating the problem.

Error messages:
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:
In member function &#8216;void std::vector<bool, _Alloc>::_M_initialize(size_t)
[with _Alloc = std::allocator<bool>]&#8217;:
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:642:
  instantiated from &#8216;std::vector<bool, _Alloc>::vector(size_t) [with
_Alloc = std::allocator<bool>]&#8217;
gcc4_template1.C:14:   instantiated from here
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:454:
error: &#8216;std::<anonymous enum>&#8217; is/uses anonymous type
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:454:
error:	 trying to instantiate &#8216;template<class T> Foo operator/(const
Foo&, T)&#8217;
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:
In member function &#8216;std::_Bit_type*
std::_Bvector_base<_Alloc>::_M_allocate(size_t) [with _Alloc =
std::allocator<bool>]&#8217;:
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:453:
  instantiated from &#8216;void std::vector<bool,
_Alloc>::_M_initialize(size_t) [with _Alloc = std::allocator<bool>]&#8217;
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:642:
  instantiated from &#8216;std::vector<bool, _Alloc>::vector(size_t) [with
_Alloc = std::allocator<bool>]&#8217;
gcc4_template1.C:14:   instantiated from here
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:387:
error: &#8216;std::<anonymous enum>&#8217; is/uses anonymous type
/data/heizer1_0/strassed/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/bits/stl_bvector.h:387:
error:	 trying to instantiate &#8216;template<class T> Foo operator/(const
Foo&, T)&#8217;
Comment 3 Andrew Pinski 2005-04-27 07:13:58 UTC
The first example is invalid is a dup of bug 19404.  Now the second example looks to be a bug in 
libstdc++.
Comment 4 Paolo Carlini 2005-04-27 08:54:04 UTC
The second example seems to me also a duplicate of 19404. This is a reduced
testcase:

class Foo { };
template<class T> void operator/(const Foo&, T);
enum { _S_word_bit = 1 };
class vector_bool
{ void _M_allocate() { (_S_word_bit - 1) / _S_word_bit; } }; 
vector_bool bar;

Andrew, can you confirm?
Comment 5 dominik.strasser 2005-04-27 09:07:58 UTC
(In reply to comment #4)
> The second example seems to me also a duplicate of 19404. This is a reduced
> testcase:
> 
> class Foo { };
> template<class T> void operator/(const Foo&, T);
> enum { _S_word_bit = 1 };
> class vector_bool
> { void _M_allocate() { (_S_word_bit - 1) / _S_word_bit; } }; 
> vector_bool bar;
> 
> Andrew, can you confirm?

The following patch cures the problem for me:
--- ./libstdc++-v3/include/bits/stl_bvector.h   2005-01-31 17:21:55.000000000 +0100
+++ /tmp/stl_bvector.h  2005-04-27 11:05:44.000000000 +0200
@@ -64,7 +64,7 @@
 namespace _GLIBCXX_STD
 {
   typedef unsigned long _Bit_type;
-  enum { _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) };
+  static const int _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type));
  
   struct _Bit_reference
   {
Comment 6 dominik.strasser 2005-04-27 09:09:28 UTC
Created attachment 8750 [details]
Use const static member instead of enum
Comment 7 Paolo Carlini 2005-04-27 09:15:31 UTC
No, we don't want to change the implementation of the library in case of user
error. Really, this is a duplicate of 19404.

*** This bug has been marked as a duplicate of 19404 ***
Comment 8 Paolo Carlini 2005-04-27 09:24:41 UTC
On second thought, maybe we can safely change the enum to not be anonymous...
Comment 9 dominik.strasser 2005-04-27 09:28:22 UTC
(In reply to comment #8)
> On second thought, maybe we can safely change the enum to not be anonymous...

I think so, too as I can't see any user error in the second example.
Comment 10 Paolo Carlini 2005-04-27 09:37:59 UTC
Yes, you are right, but I don't want to fiddle too much with that constant, in
particular risking to change its size (the standard doesn't guarantee that the
underlying type of that anonymous enum is int), seems safer just changing the
enum to be named.
Comment 11 GCC Commits 2005-04-27 15:59:40 UTC
Subject: Bug 21244

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2005-04-27 15:59:09

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: stl_bvector.h 
Added files:
	libstdc++-v3/testsuite/23_containers/vector/bool: 21244.cc 

Log message:
	2005-04-27  Dominik Strasser  <dominik.strasser@infineon.com>
	Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/21244
	* include/bits/stl_bvector.h: Change the anonymous enum
	at namespace scope to _S_word_bit_enum.
	* testsuite/23_containers/vector/bool/21244.cc: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2981&r2=1.2982
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_bvector.h.diff?cvsroot=gcc&r1=1.39&r2=1.40
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/vector/bool/21244.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 12 GCC Commits 2005-04-27 16:03:17 UTC
Subject: Bug 21244

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	paolo@gcc.gnu.org	2005-04-27 16:02:28

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: stl_bvector.h 
Added files:
	libstdc++-v3/testsuite/23_containers/vector/bool: 21244.cc 

Log message:
	2005-04-27  Dominik Strasser  <dominik.strasser@infineon.com>
	Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/21244
	* include/bits/stl_bvector.h: Change the anonymous enum
	at namespace scope to _S_word_bit_enum.
	* testsuite/23_containers/vector/bool/21244.cc: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.2917.2.31&r2=1.2917.2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_bvector.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.39&r2=1.39.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/vector/bool/21244.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 13 Paolo Carlini 2005-04-27 16:03:22 UTC
Fixed for 4.0.1.
Comment 14 GCC Commits 2005-04-28 07:51:06 UTC
Subject: Bug 21244

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2005-04-28 07:50:49

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/debug: formatter.h 
	libstdc++-v3/include/bits: cpp_type_traits.h stl_algo.h 
	                           stl_bvector.h 
	libstdc++-v3/include/ext: mt_allocator.h pool_allocator.h rope 
	                          ropeimpl.h 

Log message:
	2005-04-28  Paolo Carlini  <pcarlini@suse.de>
	Gabriel Dos Reis  <gdr@integrable-solutions.net>
	
	PR libstdc++/21244 (cont)
	* include/bits/cpp_type_traits.h (struct __traitor): Convert
	to bool the values.
	* include/bits/stl_algo.h: Convert _S_threshold to int.
	* include/bits/stl_bvector.h: Revert previous change, convert
	_S_word_bit to int.
	* include/debug/formatter.h: Convert __max_parameters to
	size_t.
	* include/ext/mt_allocator.h: Likewise for _S_chunk_size.
	* include/ext/pool_allocator.h: Likewise for _S_max_bytes and
	_S_align.
	* include/ext/rope: Likewise for _S_alloc_granularity; convert
	_S_max_rope_depth to int.
	* include/ext/ropeimpl.h: Convert _S_path_cache_len to int;
	_S_max_rope_depth to int; _S_copy_max to size_t.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2983&r2=1.2984
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/debug/formatter.h.diff?cvsroot=gcc&r1=1.8&r2=1.9
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/cpp_type_traits.h.diff?cvsroot=gcc&r1=1.16&r2=1.17
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_algo.h.diff?cvsroot=gcc&r1=1.51&r2=1.52
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_bvector.h.diff?cvsroot=gcc&r1=1.40&r2=1.41
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/mt_allocator.h.diff?cvsroot=gcc&r1=1.45&r2=1.46
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/pool_allocator.h.diff?cvsroot=gcc&r1=1.21&r2=1.22
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/rope.diff?cvsroot=gcc&r1=1.22&r2=1.23
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/ropeimpl.h.diff?cvsroot=gcc&r1=1.31&r2=1.32

Comment 15 GCC Commits 2005-04-28 08:02:47 UTC
Subject: Bug 21244

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	paolo@gcc.gnu.org	2005-04-28 08:01:36

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/debug: formatter.h 
	libstdc++-v3/include/bits: cpp_type_traits.h stl_algo.h 
	                           stl_bvector.h 
	libstdc++-v3/include/ext: mt_allocator.h pool_allocator.h rope 
	                          ropeimpl.h 

Log message:
	2005-04-28  Paolo Carlini  <pcarlini@suse.de>
	Gabriel Dos Reis  <gdr@integrable-solutions.net>
	
	PR libstdc++/21244 (cont)
	* include/bits/cpp_type_traits.h (struct __traitor): Convert
	to bool the values.
	* include/bits/stl_algo.h: Convert _S_threshold to int.
	* include/bits/stl_bvector.h: Revert previous change, convert
	_S_word_bit to int.
	* include/debug/formatter.h: Convert __max_parameters to
	size_t.
	* include/ext/mt_allocator.h: Likewise for _S_chunk_size.
	* include/ext/pool_allocator.h: Likewise for _S_max_bytes and
	_S_align.
	* include/ext/rope: Likewise for _S_alloc_granularity; convert
	_S_max_rope_depth to int.
	* include/ext/ropeimpl.h: Convert _S_path_cache_len to int;
	_S_max_rope_depth to int; _S_copy_max to size_t.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.2917.2.33&r2=1.2917.2.34
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/debug/formatter.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.8&r2=1.8.40.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/cpp_type_traits.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.16&r2=1.16.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_algo.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.50&r2=1.50.18.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_bvector.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.39.6.1&r2=1.39.6.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/mt_allocator.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.45&r2=1.45.8.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/pool_allocator.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.21&r2=1.21.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/rope.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.22&r2=1.22.8.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/ropeimpl.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.31&r2=1.31.34.1

Comment 16 GCC Commits 2005-06-29 22:12:31 UTC
Subject: Bug 21244

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2005-06-29 22:12:19

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/ext: bitmap_allocator.h 

Log message:
	2005-06-29  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/21244 (cont^2)
	* include/ext/bitmap_allocator.h: Convert everywhere
	bits_per_block to size_t.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.3051&r2=1.3052
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/bitmap_allocator.h.diff?cvsroot=gcc&r1=1.10&r2=1.11

Comment 17 GCC Commits 2005-07-11 12:05:05 UTC
Subject: Bug 21244

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	paolo@gcc.gnu.org	2005-07-11 12:04:51

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: stl_tree.h 
	libstdc++-v3/include/ext: bitmap_allocator.h 

Log message:
	2005-07-11  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/22102
	* include/bits/stl_tree.h (insert_unique(iterator, const _Val&),
	insert_equal(iterator, const _Val&)): Reimplement to check both
	before and after, as per the algorithm "ignore hint if wrong" of
	ISO paper N1780.
	
	2005-07-11  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/21244 (cont^2)
	* include/ext/bitmap_allocator.h: Convert everywhere
	bits_per_block to size_t.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.2917.2.65&r2=1.2917.2.66
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_tree.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.44.6.1&r2=1.44.6.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/ext/bitmap_allocator.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.9.12.1&r2=1.9.12.2

Comment 18 Andrew Pinski 2005-10-10 17:09:43 UTC
*** Bug 24298 has been marked as a duplicate of this bug. ***
Comment 19 dominik.strasser 2009-05-20 15:45:10 UTC
Works fine