This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problem with auto_prt copy-ctor under last several versions of g++.


This is actually a problem that's been around for a little while but I
forgot about it until just recently when I installed 2.95.1 on my
intel linux system. I've got some code that uses the auto_ptr type
defined in the include file 'memory'. My code's a bit too large to be
used as a good test case example but the issue is probably apparent to
the g++ maintainers (or is this just an STL issue?).

At line 37 of the include file 'memory' is a constructor for auto_ptr
that takes a non-const auto_ptr&. There is no explicit copy ctor that
takes a const auto_ptr&. I've got some code that uses an auto_ptr in a
map indexed by an int. I know this can result in unintended
consequences but the usage is very controlled from an external
interface. Anyway, the error I get complains about conversion from a
'const auto_ptr< Type >' to an 'auto_ptr< Type >&' discarding
qualifiers (correctly so).

My fix was to simply change the constructor to take a const reference
rather than the non-const ref. My code now builds and runs correctly
with no errors or warnings. Is this strictly a bug in the memory
include file? Was this constructor intended to be *the* copy
constructor or is there really supposed to be another constructor in
addition to the copy constructor (which the code writer probably
[incorrectly?] assumed would then be automatically generated by the
compiler)?

Appreciate comments, questions, and some kind of "fix" for the next
release.

	Ben Scherrey

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]