This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/16875] Fails to compile: STL container of const pointer to X
- From: "igodard at pacbell dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Oct 2004 02:22:22 -0000
- Subject: [Bug libstdc++/16875] Fails to compile: STL container of const pointer to X
- References: <20040804124119.16875.loose@astron.nl>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From igodard at pacbell dot net 2004-10-07 02:22 -------
For the record, the following was posted on comp.std.c++:
Try:
std::allocator<const int> a;
This fails on gcc and is permitted in icc and the other EDG derivatives. While
allocating const objects may seem non-sensical, that's what you do when you have
a standard collection of const value type. And you have (or want to have) such a
collection of const objects whenever you have a bunch of data that you want to
put in a standard collection to use standard algorithms on (say for searching)
but which will be (or should be) immutable once the collection is constructed.
g++ complains about the definition of the "address" function in std::allocator,
and the g++ folks say (in response to the PR, bug #16875; see also #17866):
"Invalid as 20.4.1 for allocator:
pointer address(reference x) const;
const_pointer address(const_reference x) const;"
However, the utility of the application is obvious and the utility of the
restriction is not, so I propose that the library specification be changed to
support allocators (and by implication collections) of const element type.
Apparently icc uses a specialization of allocator to merge the declarations of
"address" when the argument type is const, which is a pretty trivial fix. No
existing code would be invalidated by the change.
Sincerely,
Ivan Godard
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16875