The 2 source files illustrate how g++ 4.0.0 gets confused template instantiation. It tries to instantiate an unrelated template.
Created attachment 8747 [details] Source file illustrating the faulty behavior Error messages: gcc4_template.C: In function ‘void foo()’: gcc4_template.C:17: error: ‘Encoding::<anonymous enum>’ is/uses anonymous type gcc4_template.C:17: error: trying to instantiate ‘template<class T> bool operator>(const Mpz&, T)’
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 ‘void std::vector<bool, _Alloc>::_M_initialize(size_t) [with _Alloc = std::allocator<bool>]’: /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 ‘std::vector<bool, _Alloc>::vector(size_t) [with _Alloc = std::allocator<bool>]’ 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: ‘std::<anonymous enum>’ 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 ‘template<class T> Foo operator/(const Foo&, T)’ /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 ‘std::_Bit_type* std::_Bvector_base<_Alloc>::_M_allocate(size_t) [with _Alloc = std::allocator<bool>]’: /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 ‘void std::vector<bool, _Alloc>::_M_initialize(size_t) [with _Alloc = std::allocator<bool>]’ /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 ‘std::vector<bool, _Alloc>::vector(size_t) [with _Alloc = std::allocator<bool>]’ 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: ‘std::<anonymous enum>’ 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 ‘template<class T> Foo operator/(const Foo&, T)’
The first example is invalid is a dup of bug 19404. Now the second example looks to be a bug in libstdc++.
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?
(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 {
Created attachment 8750 [details] Use const static member instead of enum
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 ***
On second thought, maybe we can safely change the enum to not be anonymous...
(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.
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.
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
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
Fixed for 4.0.1.
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
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
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
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
*** Bug 24298 has been marked as a duplicate of this bug. ***
Works fine