diff options
author | Bernard Normier <bernard@zeroc.com> | 2012-08-11 15:15:53 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2012-08-11 15:15:53 -0400 |
commit | baf36f2a83903362608aa244d8f1c3c4d0e35773 (patch) | |
tree | 603b13da3589b8167bd460d9ea464a54a73b1a0d /cpp/src/slice2cpp/Gen.cpp | |
parent | implementing preserved slices in C# (diff) | |
download | ice-baf36f2a83903362608aa244d8f1c3c4d0e35773.tar.bz2 ice-baf36f2a83903362608aa244d8f1c3c4d0e35773.tar.xz ice-baf36f2a83903362608aa244d8f1c3c4d0e35773.zip |
Fixed bug #ICE-4845 (ice_clone for IceUtil::Exception is now covariant)
Small build fixes (VS warning, Python 3.x run.py)
slice2cpp no longer generates ice_clone for interfaces
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 1d713299433..7aefe066ea3 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -825,8 +825,8 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) H << nl << "virtual void ice_print(::std::ostream&) const;"; } - H << nl << "virtual ::Ice::Exception* ice_clone() const;"; - C << sp << nl << "::Ice::Exception*" << nl << scoped.substr(2) << "::ice_clone() const"; + H << nl << "virtual " << name << "* ice_clone() const;"; + C << sp << nl << scoped.substr(2) << "*" << nl << scoped.substr(2) << "::ice_clone() const"; C << sb; C << nl << "return new " << name << "(*this);"; C << eb; @@ -3559,27 +3559,37 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) if(!p->isLocal()) { - H << nl << "virtual ::Ice::ObjectPtr ice_clone() const;"; - C << sp << nl << (_dllExport.empty() ? "" : "ICE_DECLSPEC_EXPORT ") << "::Ice::Object* " << scope.substr(2) << "upCast(" << scoped << "* p) { return p; }"; - C << sp; - C << nl << "::Ice::ObjectPtr"; - C << nl << scoped.substr(2) << "::ice_clone() const"; - C << sb; - if(!p->isAbstract()) - { - C << nl << fixKwd(p->scope()) << p->name() << "Ptr __p = new " << scoped << "(*this);"; - C << nl << "return __p;"; - } - else - { - C << nl << "throw ::Ice::CloneNotImplementedException(__FILE__, __LINE__);"; - C << nl << "return 0; // to avoid a warning with some compilers"; - } - C << eb; + // + // It would make sense to provide a covariant ice_clone(); unfortunately many compilers + // (including VS2010) generate bad code for covariant types that use virtual inheritance + // + + if(!p->isInterface()) + { + H << nl << "virtual ::Ice::ObjectPtr ice_clone() const;"; + + C << nl << "::Ice::ObjectPtr"; + C << nl << scoped.substr(2) << "::ice_clone() const"; + C << sb; + if(!p->isAbstract()) + { + C << nl << "::Ice::Object* __p = new " << name << "(*this);"; + C << nl << "return __p;"; + } + else + { + // + // We need this ice_clone for abstract classes derived from concrete classes + // + C << nl << "throw ::Ice::CloneNotImplementedException(__FILE__, __LINE__);"; + C << nl << "return 0; // to avoid a warning with some compilers"; + } + C << eb; + } ClassList allBases = p->allBases(); StringList ids; |