"auto_ptr" is not the best class to use, it's functional. To correct for constant correctness issues, I wrote the following: template class auto_ptr { protected: type* p; operator type&() {return *p;} operator type() {return *p;} operator type*() {return p;} public: auto_ptr(type* pointer = 0):p(pointer){} auto_ptr(auto_ptr& source) { p = source.p; source.p=0; } ~auto_ptr(){if(p!=0)delete p;} auto_ptr& operator=(auto_ptr& source) { p = source.p; source.p=0; } operator const type&() const {return *p;} operator const type* const() const {return p;} operator type* const() const {return p;} const type& operator*() const {return *p;} type& operator*(){return *p;} type* const operator->() const {return p;} type* operator->(){return p;} }; During testing, I wrote this: global.h: class object { public: typedef auto_ptr ptr; virtual ptr clone () const { return ptr(new object(*this)); } }; main.cpp: #include "include/global.h" int main(int argc, char **argv) { } When compiling, I get this (doctored doctored my user name to 'user') : **** Build of configuration Debug for project **** make all Building file: ../main.cpp Invoking: GCC C++ Compiler g++ -I"/home/user/workspace" -O0 -g3 -Wall -c -fmessage-length=0 -v -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp" Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Finished building: ../main.cpp Building file: ../objects/map.cpp Invoking: GCC C++ Compiler g++ -I"/home/user/workspace" -O0 -g3 -Wall -c -fmessage-length=0 -v -MMD -MP -MF"objects/map.d" -MT"objects/map.d" -o"objects/map.o" "../objects/map.cpp" Thread model: posix gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC) COLLECT_GCC_OPTIONS='-I/home/user/workspace' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MFmain.d' '-MTmain.d' '-MF' 'main.d' '-MT' 'main.o' '-E' '-shared-libgcc' '-mtune=generic' /usr/libexec/gcc/x86_64-redhat-linux/4.4.3/cc1plus -E -quiet -v -I/home/user/workspace -MMD main.d -MFmain.d -MF main.d -MP -MTmain.d -MT main.o -dD -D_GNU_SOURCE ../main.cpp -mtune=generic -Wall -fmessage-length=0 -g3 -fworking-directory -O0 ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.3/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /home/user/workspace /usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../include/c++/4.4.3 /usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../include/c++/4.4.3/x86_64-redhat-linux /usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../include/c++/4.4.3/backward /usr/local/include /usr/lib/gcc/x86_64-redhat-linux/4.4.3/include /usr/include End of search list. COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/ LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-I/home/user/workspace' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MFmain.d' '-MTmain.d' '-MF' 'main.d' '-MT' 'main.o' '-E' '-shared-libgcc' '-mtune=generic' Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC) COLLECT_GCC_OPTIONS='-I/home/user/workspace' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MFmain.d' '-MTmain.d' '-MF' 'main.d' '-MT' 'main.o' '-o' '/home/user/.ccache/tmp.hash.user.12259.o' '-shared-libgcc' '-mtune=generic' /usr/libexec/gcc/x86_64-redhat-linux/4.4.3/cc1plus -fpreprocessed /home/user/.ccache/main.tmp.user.12259.ii -quiet -dumpbase main.tmp.user.12259.ii -mtune=generic -auxbase-strip /home/user/.ccache/tmp.hash.user.12259.o -g3 -O0 -Wall -version -fmessage-length=0 -o /tmp/cc0aNyRB.s GNU C++ (GCC) version 4.4.3 20100127 (Red Hat 4.4.3-4) (x86_64-redhat-linux) compiled by GNU C version 4.4.3 20100127 (Red Hat 4.4.3-4), GMP version 4.3.1, MPFR version 2.4.1. GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128063 Compiler executable checksum: dc7730975c44512cee51f44f47cd883a COLLECT_GCC_OPTIONS='-I/home/user/workspace' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MFmain.d' '-MTmain.d' '-MF' 'main.d' '-MT' 'main.o' '-o' '/home/user/.ccache/tmp.hash.user.12259.o' '-shared-libgcc' '-mtune=generic' as -V -Qy -o /home/user/.ccache/tmp.hash.user.12259.o /tmp/cc0aNyRB.s GNU assembler version 2.19.51.0.14 (x86_64-redhat-linux) using BFD version version 2.19.51.0.14-37.fc12 20090722 COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/ LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-I/home/user/workspace' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MFmain.d' '-MTmain.d' '-MF' 'main.d' '-MT' 'main.o' '-o' '/home/user/.ccache/tmp.hash.user.12259.o' '-shared-libgcc' '-mtune=generic' Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC) COLLECT_GCC_OPTIONS='-I/home/user/workspace' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MFobjects/map.d' '-MTobjects/map.d' '-MF' 'objects/map.d' '-MT' 'objects/map.o' '-E' '-shared-libgcc' '-mtune=generic' /usr/libexec/gcc/x86_64-redhat-linux/4.4.3/cc1plus -E -quiet -v -I/home/user/workspace -MMD map.d -MFobjects/map.d -MF objects/map.d -MP -MTobjects/map.d -MT objects/map.o -dD -D_GNU_SOURCE ../objects/map.cpp -mtune=generic -Wall -fmessage-length=0 -g3 -fworking-directory -O0 ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.3/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /home/user/workspace /usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../include/c++/4.4.3 /usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../include/c++/4.4.3/x86_64-redhat-linux /usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../include/c++/4.4.3/backward /usr/local/include /usr/lib/gcc/x86_64-redhat-linux/4.4.3/include /usr/include End of search list. COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.3/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/ LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.3/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-I/home/user/workspace' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MFobjects/map.d' '-MTobjects/map.d' '-MF' 'objects/map.d' '-MT' 'objects/map.o' '-E' '-shared-libgcc' '-mtune=generic' Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC) COLLECT_GCC_OPTIONS='-I/home/user/workspace' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MFobjects/map.d' '-MTobjects/map.d' '-MF' 'objects/map.d' '-MT' 'objects/map.o' '-o' '/home/user/.ccache/tmp.hash.user.12270.o' '-shared-libgcc' '-mtune=generic' /usr/libexec/gcc/x86_64-redhat-linux/4.4.3/cc1plus -fpreprocessed /home/user/.ccache/map.tmp.user.12270.ii -quiet -dumpbase map.tmp.user.12270.ii -mtune=generic -auxbase-strip /home/user/.ccache/tmp.hash.user.12270.o -g3 -O0 -Wall -version -fmessage-length=0 -o /tmp/ccb2YMZu.s GNU C++ (GCC) version 4.4.3 20100127 (Red Hat 4.4.3-4) (x86_64-redhat-linux) compiled by GNU C version 4.4.3 20100127 (Red Hat 4.4.3-4), GMP version 4.3.1, MPFR version 2.4.1. GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128063 Compiler executable checksum: dc7730975c44512cee51f44f47cd883a In file included from ../objects/map.cpp:27: ../objects/../include/global.hpp: In member function ‘virtual auto_ptr object::clone() const’: ../objects/../include/global.hpp:68: error: ‘auto_ptr::operator type*() [with type = object]’ is protected ../objects/../include/object.hpp:81: error: within this context make: *** [objects/map.o] Error 1 If I change the clone function to the following no errors are generated: virtual ptr clone () const { ptr Ret(new object(*this)); return Ret; } I am unsure why a protect type cast operator is being called by a constructor. The only place in the code that such a requirement might exist is the constructor, but it makes no sense to call the constructor or to call it in that way. -- Summary: Inconsistant and odd constructor calls. Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: stvwooddell at embarqmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43127