From https://github.com/joshmoore/zeroc-ice.git:

Patch generated with

$ git checkout Ice-3.3.1
$ git diff d9463cb5..83132b0

diff --git a/cpp/allTests.py b/cpp/allTests.py
index 257a63c..c2534b1 100755
--- a/cpp/allTests.py
+++ b/cpp/allTests.py
@@ -24,6 +24,7 @@ from scripts import *
 # List of all basic tests.
 #
 tests = [ 
+
     ("IceUtil/condvar", ["once", "win32only"]),
     ("IceUtil/thread",  ["once"]),
     ("IceUtil/unicode", ["once"]),
@@ -55,7 +56,7 @@ tests = [
     ("Ice/servantLocator", ["core"]),
     ("Ice/interceptor", ["core"]),
     ("Ice/stringConverter", ["core"]),
-    ("Ice/udp", ["core"]),
+    ("Ice/udp", ["core", "nofreebsdjail"]),
     ("IceSSL/configuration", ["once", "novalgrind"]), # valgrind doesn't work well with openssl
     ("IceBox/configuration", ["core", "noipv6"]),
     ("Freeze/dbmap", ["once"]),
diff --git a/cpp/include/Freeze/Map.h b/cpp/include/Freeze/Map.h
index c51e867..8d7f4f8 100644
--- a/cpp/include/Freeze/Map.h
+++ b/cpp/include/Freeze/Map.h
@@ -426,7 +426,7 @@ public:
 
     ConstIterator(MapHelper& mapHelper, const Ice::CommunicatorPtr& communicator) :
         _helper(IteratorHelper::create(mapHelper, true)), 
-        _communicator(_communicator),
+        _communicator(communicator),
         _refValid(false)
     {
     }
diff --git a/cpp/include/Ice/Buffer.h b/cpp/include/Ice/Buffer.h
index 1f9a029..41dabc0 100644
--- a/cpp/include/Ice/Buffer.h
+++ b/cpp/include/Ice/Buffer.h
@@ -10,6 +10,7 @@
 #ifndef ICEE_BUFFER_H
 #define ICEE_BUFFER_H
 
+#include <cstddef>
 #include <Ice/Config.h>
 
 namespace IceInternal
diff --git a/cpp/include/Ice/ConnectionIF.h b/cpp/include/Ice/ConnectionIF.h
index 8d7f8df..795f8e1 100644
--- a/cpp/include/Ice/ConnectionIF.h
+++ b/cpp/include/Ice/ConnectionIF.h
@@ -17,13 +17,13 @@ namespace Ice
 {
 
 class ConnectionI;
+ICE_API Ice::LocalObject* upCast(Ice::ConnectionI*);
 
 }
 
 namespace IceInternal
 {
 
-ICE_API Ice::LocalObject* upCast(Ice::ConnectionI*);
 
 }
 
diff --git a/cpp/include/Ice/IconvStringConverter.h b/cpp/include/Ice/IconvStringConverter.h
index 56f8309..13740ad 100644
--- a/cpp/include/Ice/IconvStringConverter.h
+++ b/cpp/include/Ice/IconvStringConverter.h
@@ -225,10 +225,16 @@ IconvStringConverter<charT>::cleanupKey(void* val)
 template<typename charT> /*static*/ void
 IconvStringConverter<charT>::close(std::pair<iconv_t, iconv_t> cdp)
 {
-    int rs = iconv_close(cdp.first);
+#ifndef NDEBUG
+    int rs = 
+#endif
+    iconv_close(cdp.first);
     assert(rs == 0);
 
-    rs = iconv_close(cdp.second);
+#ifndef NDEBUG
+    rs = 
+#endif
+    iconv_close(cdp.second);
     assert(rs == 0);
 }
  
diff --git a/cpp/include/Ice/IncomingAsyncF.h b/cpp/include/Ice/IncomingAsyncF.h
index e123d7b..38d55c6 100644
--- a/cpp/include/Ice/IncomingAsyncF.h
+++ b/cpp/include/Ice/IncomingAsyncF.h
@@ -28,12 +28,6 @@ namespace Ice
 
 class AMD_Object_ice_invoke;
 class AMD_Array_Object_ice_invoke;
-
-}
-
-namespace IceInternal
-{
-
 ICE_API IceUtil::Shared* upCast(::Ice::AMD_Object_ice_invoke*);
 ICE_API IceUtil::Shared* upCast(::Ice::AMD_Array_Object_ice_invoke*);
 
diff --git a/cpp/include/Ice/LocalObjectF.h b/cpp/include/Ice/LocalObjectF.h
index 5601e3c..310072b 100644
--- a/cpp/include/Ice/LocalObjectF.h
+++ b/cpp/include/Ice/LocalObjectF.h
@@ -18,12 +18,6 @@ namespace Ice
 {
 
 class LocalObject;
-
-}
-
-namespace IceInternal
-{
-
 ICE_API IceUtil::Shared* upCast(::Ice::LocalObject*);
 
 }
diff --git a/cpp/include/Ice/ObjectF.h b/cpp/include/Ice/ObjectF.h
index 1d83231..cbd067d 100644
--- a/cpp/include/Ice/ObjectF.h
+++ b/cpp/include/Ice/ObjectF.h
@@ -19,19 +19,9 @@ namespace Ice
 
 class Object;
 
-}
-
-namespace IceInternal
-{
-
-ICE_API GCShared* upCast(::Ice::Object*);
-
-}
-
-namespace Ice
-{
+ICE_API IceUtil::Shared* upCast(::Ice::Object*);
 
-typedef IceInternal::Handle< Object > ObjectPtr;
+typedef IceInternal::Handle< ::Ice::Object > ObjectPtr;
 
 void ICE_API __patch__ObjectPtr(void*, ObjectPtr&);
 
diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h
index 3fc321a..75bcbde 100644
--- a/cpp/include/Ice/Proxy.h
+++ b/cpp/include/Ice/Proxy.h
@@ -37,6 +37,8 @@ namespace Ice
 
 class Locator;
 class Router;
+ICE_API ::IceProxy::Ice::Object* upCast(::IceProxy::Ice::Locator*);
+ICE_API ::IceProxy::Ice::Object* upCast(::IceProxy::Ice::Router*);
 
 }
 
@@ -45,8 +47,6 @@ class Router;
 namespace IceInternal
 {
 
-ICE_API ::IceProxy::Ice::Object* upCast(::IceProxy::Ice::Locator*);
-ICE_API ::IceProxy::Ice::Object* upCast(::IceProxy::Ice::Router*);
 
 class LocalExceptionWrapper;
 
diff --git a/cpp/include/Ice/ProxyF.h b/cpp/include/Ice/ProxyF.h
index 8a9184b..1142c1a 100644
--- a/cpp/include/Ice/ProxyF.h
+++ b/cpp/include/Ice/ProxyF.h
@@ -22,6 +22,11 @@ namespace Ice
 {
 
 class Object;
+inline ::IceProxy::Ice::Object* 
+upCast(::IceProxy::Ice::Object* o)
+{
+    return o;
+}
 
 }
 
@@ -34,6 +39,11 @@ namespace Ice
 {
 
 class Object;
+inline ::IceDelegate::Ice::Object*
+upCast(::IceDelegate::Ice::Object* o)
+{
+    return o;
+}
 
 }
 
@@ -47,6 +57,12 @@ namespace Ice
 
 class Object;
 
+inline ::IceDelegateM::Ice::Object*
+upCast(::IceDelegateM::Ice::Object* o)
+{
+    return o;
+}
+
 }
 
 }
@@ -58,36 +74,12 @@ namespace Ice
 {
 
 class Object;
-
-}
-
-}
-
-namespace IceInternal
-{
-
-inline ::IceProxy::Ice::Object* 
-upCast(::IceProxy::Ice::Object* o)
-{
-    return o;
-}
-
-inline ::IceDelegate::Ice::Object*
-upCast(::IceDelegate::Ice::Object* o)
-{
-    return o;
-}
-
 inline ::IceDelegateD::Ice::Object*
 upCast(::IceDelegateD::Ice::Object* o)
 {
     return o;
 }
 
-inline ::IceDelegateM::Ice::Object*
-upCast(::IceDelegateM::Ice::Object* o)
-{
-    return o;
 }
 
 }
diff --git a/cpp/include/Ice/Stream.h b/cpp/include/Ice/Stream.h
index a4f3d57..fb9d29f 100644
--- a/cpp/include/Ice/Stream.h
+++ b/cpp/include/Ice/Stream.h
@@ -16,8 +16,15 @@
 #include <Ice/Exception.h>
 #include <IceUtil/Shared.h>
 
+namespace IceInternal
+{
+    // Forward declaration required for writer specializations.
+    void delegateThrowMarshalException(const char*, int, const ::std::string&);
+}
+
 namespace Ice
 {
+    
 
 class ICE_API ReadObjectCallback : public ::IceUtil::Shared
 {
diff --git a/cpp/include/Ice/StreamF.h b/cpp/include/Ice/StreamF.h
index a938e7e..886eb1b 100644
--- a/cpp/include/Ice/StreamF.h
+++ b/cpp/include/Ice/StreamF.h
@@ -19,12 +19,6 @@ namespace Ice
 
 class InputStream;
 class OutputStream;
-
-}
-
-namespace IceInternal
-{
-
 ICE_API IceUtil::Shared* upCast(::Ice::InputStream*);
 ICE_API IceUtil::Shared* upCast(::Ice::OutputStream*);
 
diff --git a/cpp/include/IceUtil/Mutex.h b/cpp/include/IceUtil/Mutex.h
index af0c709..5c789c6 100644
--- a/cpp/include/IceUtil/Mutex.h
+++ b/cpp/include/IceUtil/Mutex.h
@@ -200,8 +200,11 @@ Mutex::Mutex()
 inline
 Mutex::~Mutex()
 {
+#ifndef NDEBUG
     int rc = 0;
-    rc = pthread_mutex_destroy(&_mutex);
+    rc = 
+#endif    
+    pthread_mutex_destroy(&_mutex);
     assert(rc == 0);
 }
 
diff --git a/cpp/src/Freeze/MapDb.cpp b/cpp/src/Freeze/MapDb.cpp
index 1978575..919b736 100644
--- a/cpp/src/Freeze/MapDb.cpp
+++ b/cpp/src/Freeze/MapDb.cpp
@@ -226,7 +226,11 @@ Freeze::MapDb::MapDb(const ConnectionIPtr& connection,
 #ifndef NDEBUG
                 bool inserted = 
 #endif
-                    _indices.insert(IndexMap::value_type(indexBase->name(), indexI.get())).second;
+                    _indices.insert(IndexMap::value_type(indexBase->name(), indexI.get()))
+#ifndef NDEBUG                    
+                    .second
+#endif
+                ;
                 assert(inserted);
                 
                 indexBase->_impl = indexI.release();
diff --git a/cpp/src/Freeze/MapI.cpp b/cpp/src/Freeze/MapI.cpp
index 2258903..a64c5f0 100644
--- a/cpp/src/Freeze/MapI.cpp
+++ b/cpp/src/Freeze/MapI.cpp
@@ -744,8 +744,11 @@ Freeze::IteratorHelperI::set(const Value& value)
 
     try
     {
+#ifndef NDEBUG
         int err;
-        err = _dbc->put(&dbKey, &dbValue, DB_CURRENT);
+        err = 
+#endif
+        _dbc->put(&dbKey, &dbValue, DB_CURRENT);
         assert(err == 0);
     }
     catch(const ::DbDeadlockException& dx)
@@ -1018,7 +1021,11 @@ Freeze::MapHelperI::MapHelperI(const ConnectionIPtr& connection,
 #ifndef NDEBUG
         bool inserted =
 #endif 
-            _indices.insert(IndexMap::value_type(indexBase->name(), indexBase)).second;
+            _indices.insert(IndexMap::value_type(indexBase->name(), indexBase))
+#ifndef NDEBUG
+            .second
+#endif
+            ;
         assert(inserted);
         indexBase->_map = this;
     }
@@ -1355,8 +1362,11 @@ Freeze::MapHelperI::clear()
         try
         {
             u_int32_t count;
+#ifndef NDEBUG
             int err;
-            err = _db->truncate(txn, &count, txn != 0 ? 0 : DB_AUTO_COMMIT);
+            err = 
+#endif            
+            _db->truncate(txn, &count, txn != 0 ? 0 : DB_AUTO_COMMIT);
             assert(err == 0);
             break;
         }
diff --git a/cpp/src/Freeze/SharedDbEnv.cpp b/cpp/src/Freeze/SharedDbEnv.cpp
index b163fbe..fb91fbd 100644
--- a/cpp/src/Freeze/SharedDbEnv.cpp
+++ b/cpp/src/Freeze/SharedDbEnv.cpp
@@ -285,8 +285,11 @@ void Freeze::SharedDbEnv::__decRef()
         // Remove from map
         //
      
+#ifndef NDEBUG
         size_t one;
-        one = sharedDbEnvMap->erase(key);
+        one = 
+#endif
+        sharedDbEnvMap->erase(key);
         assert(one == 1);
 
         if(sharedDbEnvMap->size() == 0)
diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp
index 224fbf3..a9f73a7 100644
--- a/cpp/src/Ice/ConnectionI.cpp
+++ b/cpp/src/Ice/ConnectionI.cpp
@@ -32,7 +32,7 @@ using namespace std;
 using namespace Ice;
 using namespace IceInternal;
 
-Ice::LocalObject* IceInternal::upCast(ConnectionI* p) { return p; }
+Ice::LocalObject* Ice::upCast(ConnectionI* p) { return p; }
 
 namespace IceInternal
 {
diff --git a/cpp/src/Ice/IncomingAsync.cpp b/cpp/src/Ice/IncomingAsync.cpp
index 5324af0..6032f20 100644
--- a/cpp/src/Ice/IncomingAsync.cpp
+++ b/cpp/src/Ice/IncomingAsync.cpp
@@ -23,8 +23,8 @@ using namespace Ice;
 using namespace IceInternal;
 
 IceUtil::Shared* IceInternal::upCast(IncomingAsync* p) { return p; }
-IceUtil::Shared* IceInternal::upCast(AMD_Object_ice_invoke* p) { return p; }
-IceUtil::Shared* IceInternal::upCast(AMD_Array_Object_ice_invoke* p) { return p; }
+IceUtil::Shared* Ice::upCast(AMD_Object_ice_invoke* p) { return p; }
+IceUtil::Shared* Ice::upCast(AMD_Array_Object_ice_invoke* p) { return p; }
 
 IceInternal::IncomingAsync::IncomingAsync(Incoming& in) :
     IncomingBase(in),
diff --git a/cpp/src/Ice/LocalObject.cpp b/cpp/src/Ice/LocalObject.cpp
index 16e57a3..d62a9ab 100644
--- a/cpp/src/Ice/LocalObject.cpp
+++ b/cpp/src/Ice/LocalObject.cpp
@@ -13,7 +13,7 @@ using namespace std;
 using namespace Ice;
 using namespace IceInternal;
 
-IceUtil::Shared* IceInternal::upCast(LocalObject* obj) { return obj; }
+IceUtil::Shared* Ice::upCast(LocalObject* obj) { return obj; }
 
 bool
 Ice::LocalObject::operator==(const LocalObject& r) const
diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp
index 5ab0149..20ba411 100644
--- a/cpp/src/Ice/Object.cpp
+++ b/cpp/src/Ice/Object.cpp
@@ -19,7 +19,7 @@ using namespace std;
 using namespace Ice;
 using namespace IceInternal;
 
-IceInternal::GCShared* IceInternal::upCast(Object* p) { return p; }
+IceUtil::Shared* Ice::upCast(Object* p) { return p; }
 
 bool
 Ice::Object::operator==(const Object& r) const
diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp
index 0acc851..466da13 100644
--- a/cpp/src/Ice/Service.cpp
+++ b/cpp/src/Ice/Service.cpp
@@ -1943,17 +1943,26 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
             //
             // Associate stdin, stdout and stderr with /dev/null.
             //
+#ifndef NDEBUG
             int fd;
-            fd = open("/dev/null", O_RDWR);
+            fd = 
+#endif
+            open("/dev/null", O_RDWR);
             assert(fd == 0);
             if(stdOut.empty())
             {
-                fd = dup2(0, 1);
+#ifndef NDEBUG
+                fd = 
+#endif
+                dup2(0, 1);
                 assert(fd == 1);
             }
             if(stdErr.empty())
             {
-                fd = dup2(1, 2);
+#ifndef NDEBUG
+                fd = 
+#endif
+                dup2(1, 2);
                 assert(fd == 2);
             }
         }
diff --git a/cpp/src/Ice/Stream.cpp b/cpp/src/Ice/Stream.cpp
index 20825a9..fbe208f 100644
--- a/cpp/src/Ice/Stream.cpp
+++ b/cpp/src/Ice/Stream.cpp
@@ -8,13 +8,14 @@
 // **********************************************************************
 
 #include <Ice/Stream.h>
+#include <Ice/LocalException.h>
 
 using namespace std;
 using namespace Ice;
 using namespace IceInternal;
 
-IceUtil::Shared* IceInternal::upCast(InputStream* p) { return p; }
-IceUtil::Shared* IceInternal::upCast(OutputStream* p) { return p; }
+IceUtil::Shared* Ice::upCast(InputStream* p) { return p; }
+IceUtil::Shared* Ice::upCast(OutputStream* p) { return p; }
 
 Ice::ReadObjectCallbackI::ReadObjectCallbackI(PatchFunc func, void* arg) :
     _func(func), _arg(arg)
diff --git a/cpp/src/IceGrid/AdminCallbackRouter.cpp b/cpp/src/IceGrid/AdminCallbackRouter.cpp
index 03d7481..6029799 100644
--- a/cpp/src/IceGrid/AdminCallbackRouter.cpp
+++ b/cpp/src/IceGrid/AdminCallbackRouter.cpp
@@ -49,7 +49,12 @@ IceGrid::AdminCallbackRouter::addMapping(const string& category, const Connectio
 #ifndef NDEBUG
     bool inserted =
 #endif
-        _categoryToConnection.insert(map<string, ConnectionPtr>::value_type(category, con)).second;
+        _categoryToConnection.insert(map<string, ConnectionPtr>::value_type(category, con))
+#ifndef NDEBUG
+        .second
+#endif
+        ;
+
     
     assert(inserted == true);
 }
diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp
index 5fb6b0f..f732958 100644
--- a/cpp/src/IceGrid/DescriptorHelper.cpp
+++ b/cpp/src/IceGrid/DescriptorHelper.cpp
@@ -198,15 +198,6 @@ updateSeqElts(const Seq& seq, const Seq& update, const Ice::StringSeq& remove, G
     return result;
 }
 
-template<typename Dict> Dict
-getDictUpdatedElts(const Dict& ldict, const Dict& rdict)
-{
-#if defined(_MSC_VER) && (_MSC_VER < 1300)
-    return getDictUpdatedEltsWithEq(ldict, rdict, equal_to<Dict::mapped_type>());
-#else
-    return getDictUpdatedEltsWithEq(ldict, rdict, equal_to<typename Dict::mapped_type>());
-#endif
-}
 
 template<typename EqFunc, typename Dict> Dict
 getDictUpdatedEltsWithEq(const Dict& ldict, const Dict& rdict, EqFunc eq)
@@ -223,6 +214,16 @@ getDictUpdatedEltsWithEq(const Dict& ldict, const Dict& rdict, EqFunc eq)
     return result;
 }
 
+template<typename Dict> Dict
+getDictUpdatedElts(const Dict& ldict, const Dict& rdict)
+{
+#if defined(_MSC_VER) && (_MSC_VER < 1300)
+    return getDictUpdatedEltsWithEq(ldict, rdict, equal_to<Dict::mapped_type>());
+#else
+    return getDictUpdatedEltsWithEq(ldict, rdict, equal_to<typename Dict::mapped_type>());
+#endif
+}
+
 template <typename Dict> Ice::StringSeq
 getDictRemovedElts(const Dict& ldict, const Dict& rdict)
 {
diff --git a/cpp/src/IceGrid/ReplicaCache.cpp b/cpp/src/IceGrid/ReplicaCache.cpp
index 40e4e06..a67f04b 100644
--- a/cpp/src/IceGrid/ReplicaCache.cpp
+++ b/cpp/src/IceGrid/ReplicaCache.cpp
@@ -40,7 +40,7 @@ ReplicaCache::add(const string& name, const ReplicaSessionIPtr& session)
     Lock sync(*this);
     
     ReplicaEntryPtr entry;
-    while(entry = getImpl(name))
+    while((entry = getImpl(name)))
     {
         ReplicaSessionIPtr session = entry->getSession();
         if(session->isDestroyed())
diff --git a/cpp/src/IceGrid/SessionI.h b/cpp/src/IceGrid/SessionI.h
index 406ebf3..5a793e3 100644
--- a/cpp/src/IceGrid/SessionI.h
+++ b/cpp/src/IceGrid/SessionI.h
@@ -35,7 +35,7 @@ typedef IceUtil::Handle<Allocatable> AllocatablePtr;
 class SessionI;
 typedef IceUtil::Handle<SessionI> SessionIPtr;
 
-class BaseSessionI : virtual Ice::Object, public IceUtil::Mutex
+class BaseSessionI : virtual public Ice::Object, public IceUtil::Mutex
 {
 public:
 
diff --git a/cpp/src/IceSSL/Instance.cpp b/cpp/src/IceSSL/Instance.cpp
index 47f40cf..0acca6a 100644
--- a/cpp/src/IceSSL/Instance.cpp
+++ b/cpp/src/IceSSL/Instance.cpp
@@ -31,7 +31,7 @@ using namespace std;
 using namespace Ice;
 using namespace IceSSL;
 
-IceUtil::Shared* IceInternal::upCast(IceSSL::Instance* p) { return p; }
+IceUtil::Shared* IceSSL::upCast(IceSSL::Instance* p) { return p; }
 
 static IceUtil::StaticMutex staticMutex = ICE_STATIC_MUTEX_INITIALIZER;
 static int instanceCount = 0;
diff --git a/cpp/src/IceSSL/InstanceF.h b/cpp/src/IceSSL/InstanceF.h
index 47b29b3..1e09d1c 100644
--- a/cpp/src/IceSSL/InstanceF.h
+++ b/cpp/src/IceSSL/InstanceF.h
@@ -18,13 +18,13 @@ namespace IceSSL
 {
 
 class Instance;
+IceUtil::Shared* upCast(IceSSL::Instance*);
 
 }
 
 namespace IceInternal
 {
 
-IceUtil::Shared* upCast(IceSSL::Instance*);
 
 }
 
diff --git a/cpp/src/IceSSL/TrustManager.cpp b/cpp/src/IceSSL/TrustManager.cpp
index dbafb0a..4c7471a 100644
--- a/cpp/src/IceSSL/TrustManager.cpp
+++ b/cpp/src/IceSSL/TrustManager.cpp
@@ -20,7 +20,7 @@
 using namespace std;
 using namespace IceSSL;
 
-IceUtil::Shared* IceInternal::upCast(IceSSL::TrustManager* p) { return p; }
+IceUtil::Shared* IceSSL::upCast(IceSSL::TrustManager* p) { return p; }
 
 TrustManager::TrustManager(const Ice::CommunicatorPtr& communicator) :
     _communicator(communicator)
diff --git a/cpp/src/IceSSL/TrustManagerF.h b/cpp/src/IceSSL/TrustManagerF.h
index 46dac9c..94f5f0d 100644
--- a/cpp/src/IceSSL/TrustManagerF.h
+++ b/cpp/src/IceSSL/TrustManagerF.h
@@ -18,13 +18,13 @@ namespace IceSSL
 {
 
 class TrustManager;
+IceUtil::Shared* upCast(IceSSL::TrustManager*);
 
 }
 
 namespace IceInternal
 {
 
-IceUtil::Shared* upCast(IceSSL::TrustManager*);
 
 }
 
diff --git a/cpp/src/IceSSL/Util.cpp b/cpp/src/IceSSL/Util.cpp
index ca11f1c..d3d9fe6 100644
--- a/cpp/src/IceSSL/Util.cpp
+++ b/cpp/src/IceSSL/Util.cpp
@@ -171,7 +171,7 @@ convertDH(unsigned char* p, int plen, unsigned char* g, int glen)
     return dh;
 }
 
-IceUtil::Shared* IceInternal::upCast(IceSSL::DHParams* p) { return p; }
+IceUtil::Shared* IceSSL::upCast(IceSSL::DHParams* p) { return p; }
 
 IceSSL::DHParams::DHParams() :
     _dh512(0), _dh1024(0), _dh2048(0), _dh4096(0)
diff --git a/cpp/src/IceSSL/UtilF.h b/cpp/src/IceSSL/UtilF.h
index 053aa96..7e045cb 100644
--- a/cpp/src/IceSSL/UtilF.h
+++ b/cpp/src/IceSSL/UtilF.h
@@ -21,13 +21,13 @@ namespace IceSSL
 {
 
 class DHParams;
+IceUtil::Shared* upCast(IceSSL::DHParams*);
 
 }
 
 namespace IceInternal
 {
 
-IceUtil::Shared* upCast(IceSSL::DHParams*);
 
 }
 
diff --git a/cpp/src/IceStorm/NodeI.cpp b/cpp/src/IceStorm/NodeI.cpp
index ea3e278..d03cc90 100644
--- a/cpp/src/IceStorm/NodeI.cpp
+++ b/cpp/src/IceStorm/NodeI.cpp
@@ -18,11 +18,6 @@ using namespace std;
 namespace
 {
 
-bool operator==(const GroupNodeInfo& info, int id)
-{
-    return info.id == id;
-}
-
 class CheckTask : public IceUtil::TimerTask
 {
     const NodeIPtr _node;
diff --git a/cpp/src/IceUtil/Cond.cpp b/cpp/src/IceUtil/Cond.cpp
index 34be360..936eb44 100644
--- a/cpp/src/IceUtil/Cond.cpp
+++ b/cpp/src/IceUtil/Cond.cpp
@@ -330,8 +330,11 @@ IceUtil::Cond::Cond()
 
 IceUtil::Cond::~Cond()
 {
+#ifndef NDEBUG
     int rc = 0;
-    rc = pthread_cond_destroy(&_cond);
+    rc = 
+#endif
+    pthread_cond_destroy(&_cond);
     assert(rc == 0);
 }
 
diff --git a/cpp/src/IceUtil/CountDownLatch.cpp b/cpp/src/IceUtil/CountDownLatch.cpp
index fe3eac8..9ac0eb3 100644
--- a/cpp/src/IceUtil/CountDownLatch.cpp
+++ b/cpp/src/IceUtil/CountDownLatch.cpp
@@ -44,10 +44,16 @@ IceUtilInternal::CountDownLatch::~CountDownLatch()
 #ifdef _WIN32
     CloseHandle(_event);
 #else
+#ifndef NDEBUG
     int rc = 0;
-    rc = pthread_mutex_destroy(&_mutex);
+    rc = 
+#endif
+    pthread_mutex_destroy(&_mutex);
     assert(rc == 0);
-    rc = pthread_cond_destroy(&_cond);
+#ifndef NDEBUG
+    rc = 
+#endif
+    pthread_cond_destroy(&_cond);
     assert(rc == 0);
 #endif
 }
diff --git a/cpp/src/IceUtil/CtrlCHandler.cpp b/cpp/src/IceUtil/CtrlCHandler.cpp
index 5901722..d8a3c42 100644
--- a/cpp/src/IceUtil/CtrlCHandler.cpp
+++ b/cpp/src/IceUtil/CtrlCHandler.cpp
@@ -181,29 +181,41 @@ CtrlCHandler::CtrlCHandler(CtrlCHandlerCallback callback)
         sigaddset(&ctrlCLikeSignals, SIGHUP);
         sigaddset(&ctrlCLikeSignals, SIGINT);
         sigaddset(&ctrlCLikeSignals, SIGTERM);
-        int rc = pthread_sigmask(SIG_BLOCK, &ctrlCLikeSignals, 0);
+#ifndef NDEBUG
+        int rc = 
+#endif        
+        pthread_sigmask(SIG_BLOCK, &ctrlCLikeSignals, 0);
         assert(rc == 0);
 
         // Joinable thread
-        rc = pthread_create(&_tid, 0, sigwaitThread, 0);
+#ifndef NDEBUG
+        rc = 
+#endif
+        pthread_create(&_tid, 0, sigwaitThread, 0);
         assert(rc == 0);
     }
 }
 
 CtrlCHandler::~CtrlCHandler()
 {
-    int rc = pthread_cancel(_tid);
+#ifndef NDEBUG
+    int rc = 
+#endif
+    pthread_cancel(_tid);
     assert(rc == 0);
 #if defined(__APPLE__)
     //
     // WORKAROUND: sigwait isn't a cancellation point on MacOS X, see
     // comment in sigwaitThread
     //
-    rc = pthread_kill(_tid, SIGTERM);
+    pthread_kill(_tid, SIGTERM);
     //assert(rc == 0); For some reaosns, this assert is sometime triggered
 #endif
     void* status = 0;
-    rc = pthread_join(_tid, &status);
+#ifndef NDEBUG
+    rc = 
+#endif
+    pthread_join(_tid, &status);
     assert(rc == 0);
 #if !defined(__APPLE__)
     assert(status == PTHREAD_CANCELED);
diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp
index ac83006..c379d54 100644
--- a/cpp/src/IceUtil/FileUtil.cpp
+++ b/cpp/src/IceUtil/FileUtil.cpp
@@ -9,6 +9,10 @@
 
 #include <IceUtil/FileUtil.h>
 
+#ifdef __FreeBSD__
+#  include <unistd.h>
+#endif
+
 using namespace std;
 
 //
diff --git a/cpp/src/IceUtil/RecMutex.cpp b/cpp/src/IceUtil/RecMutex.cpp
index 666f2ed..39e1172 100644
--- a/cpp/src/IceUtil/RecMutex.cpp
+++ b/cpp/src/IceUtil/RecMutex.cpp
@@ -117,8 +117,11 @@ IceUtil::RecMutex::RecMutex() :
 IceUtil::RecMutex::~RecMutex()
 {
     assert(_count == 0);
+#ifndef NDEBUG
     int rc = 0;
-    rc = pthread_mutex_destroy(&_mutex);
+    rc = 
+#endif
+    pthread_mutex_destroy(&_mutex);
     assert(rc == 0);
 }
 
@@ -165,8 +168,11 @@ IceUtil::RecMutex::unlock() const
 {
     if(--_count == 0)
     {
+#ifndef NDEBUG
         int rc = 0; // Prevent warnings when NDEBUG is defined.
-        rc = pthread_mutex_unlock(&_mutex);
+        rc = 
+#endif
+        pthread_mutex_unlock(&_mutex);
         assert(rc == 0);
     }
 }
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 507faac..2da4e5f 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -643,7 +643,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string&
         string scope = fixKwd(cl->scope());
         if(marshal)
         {
-            out << nl << stream << deref << "write(::Ice::ObjectPtr(::IceInternal::upCast(" << fixedParam 
+            out << nl << stream << deref << "write(::Ice::ObjectPtr(" << scope << "upCast(" << fixedParam 
                 << ".get())));";
         }
         else
@@ -661,7 +661,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string&
         string scope = fixKwd(px->_class()->scope());
         if(marshal)
         {
-            out << nl << stream << deref << "write(::Ice::ObjectPrx(::IceInternal::upCast(" << fixedParam 
+            out << nl << stream << deref << "write(::Ice::ObjectPrx(::IceProxy" << scope << "upCast(" << fixedParam 
                 << ".get())));";
         }
         else
diff --git a/cpp/src/Slice/FileTracker.cpp b/cpp/src/Slice/FileTracker.cpp
index 2d4ce22..026e3d9 100644
--- a/cpp/src/Slice/FileTracker.cpp
+++ b/cpp/src/Slice/FileTracker.cpp
@@ -17,6 +17,10 @@
 #   include <direct.h>
 #endif
 
+#ifdef __FreeBSD__
+#   include <unistd.h>
+#endif
+
 using namespace std;
 
 Slice::FileException::FileException(const char* file, int line, const string& r) :
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 1beb938..4518472 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -1813,8 +1813,10 @@ Slice::Gen::ProxyDeclVisitor::visitClassDecl(const ClassDeclPtr& p)
     }
 
     string name = fixKwd(p->name());
+    string scoped = fixKwd(p->scoped());
 
     H << sp << nl << "class " << name << ';';
+    H << nl << _dllExport << "::IceProxy::Ice::Object* upCast(::IceProxy" << scoped << "*);";
 }
 
 Slice::Gen::ProxyVisitor::ProxyVisitor(Output& h, Output& c, const string& dllExport) :
@@ -3239,10 +3241,22 @@ void
 Slice::Gen::ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p)
 {
     string name = fixKwd(p->name());
+    string scoped = fixKwd(p->scoped());
 
     H << sp << nl << "class " << name << ';';
-    H << nl << _dllExport << "bool operator==(const " << name << "&, const " << name << "&);";
-    H << nl << _dllExport << "bool operator<(const " << name << "&, const " << name << "&);";
+    H << nl << "bool operator==(const " << name << "&, const " << name << "&);";
+    H << nl << "bool operator<(const " << name << "&, const " << name << "&);";
+
+    H << sp;
+
+    if(!p->isLocal())
+    {
+        H << nl << _dllExport << "::Ice::Object* upCast(" << scoped << "*);";
+    }
+    else
+    {
+        H << nl << _dllExport << "::Ice::LocalObject* upCast(" << scoped << "*);";
+    }
 }
 
 void
@@ -4390,13 +4404,13 @@ Slice::Gen::ObjectVisitor::emitGCInsertCode(const TypePtr& p, const string& pref
 {
     if((BuiltinPtr::dynamicCast(p) && BuiltinPtr::dynamicCast(p)->kind() == Builtin::KindObject)
        || ClassDeclPtr::dynamicCast(p))
-    {
-        C << nl << "if(" << prefix << name << ')';
+    {        C << nl << "if(" << prefix << name << ')';
         C << sb;
         ClassDeclPtr decl = ClassDeclPtr::dynamicCast(p);
         if(decl)
         {
-            C << nl << "::IceInternal::upCast(" << prefix << name << ".get())->__addObject(_c);";
+            string scope = fixKwd(decl->scope());
+            C << nl << scope << "upCast(" << prefix << name << ".get())->__addObject(_c);";
         }
         else
         {
@@ -4459,9 +4473,10 @@ Slice::Gen::ObjectVisitor::emitGCClearCode(const TypePtr& p, const string& prefi
         ClassDeclPtr decl = ClassDeclPtr::dynamicCast(p);
         if(decl)
         {
-            C << nl << "if(" << "::IceInternal::upCast(" << prefix << name << ".get())->__usesClasses())";
+            string scope = fixKwd(decl->scope());
+            C << nl << "if(" << scope << "upCast(" << prefix << name << ".get())->__usesClasses())";
             C << sb;
-            C << nl << "::IceInternal::upCast(" << prefix << name << ".get())->__decRefUnsafe();";
+            C << nl << scope << "upCast(" << prefix << name << ".get())->__decRefUnsafe();";
             C << nl << prefix << name << ".__clearHandleUnsafe();";
 
         }
@@ -4671,40 +4686,30 @@ Slice::Gen::IceInternalVisitor::visitClassDecl(const ClassDeclPtr& p)
 {
     string scoped = fixKwd(p->scoped());
 
-    H << sp;
-
-    if(!p->isLocal())
-    {
-        H << nl << _dllExport << "::Ice::Object* upCast(" << scoped << "*);";
-        H << nl << _dllExport << "::IceProxy::Ice::Object* upCast(::IceProxy" << scoped << "*);";
-    }
-    else
-    {
-        H << nl << _dllExport << "::Ice::LocalObject* upCast(" << scoped << "*);";
-    }
 }
 
 bool
 Slice::Gen::IceInternalVisitor::visitClassDefStart(const ClassDefPtr& p)
 {
     string scoped = fixKwd(p->scoped());
+    string scope = fixKwd(p->scope());
 
     C << sp;
     if(!p->isLocal())
     {
         C << nl
 	  << (_dllExport.empty() ? "" : "ICE_DECLSPEC_EXPORT ")
-	  << "::Ice::Object* IceInternal::upCast(" << scoped << "* p) { return p; }";
+	  << "::Ice::Object* " << scope << "upCast(" << scoped << "* p) { return p; }";
         C << nl
 	  << (_dllExport.empty() ? "" : "ICE_DECLSPEC_EXPORT ")
-	  << "::IceProxy::Ice::Object* IceInternal::upCast(::IceProxy" << scoped
+	  << "::IceProxy::Ice::Object* IceProxy" << scope << "upCast(::IceProxy" << scoped
           << "* p) { return p; }";
     }
     else
     {
         C << nl
 	  << (_dllExport.empty() ? "" : "ICE_DECLSPEC_EXPORT ")
-	  << "::Ice::LocalObject* IceInternal::upCast(" << scoped << "* p) { return p; }";
+	  << "::Ice::LocalObject* " << scope << "upCast(" << scoped << "* p) { return p; }";
     }
 
     return true;
diff --git a/cpp/test/Ice/background/EndpointI.h b/cpp/test/Ice/background/EndpointI.h
index 65c7d47..2be2bb3 100644
--- a/cpp/test/Ice/background/EndpointI.h
+++ b/cpp/test/Ice/background/EndpointI.h
@@ -45,7 +45,7 @@ public:
 protected:
 
 #if !defined(_MSC_VER) || _MSC_VER > 1300
-    using IceInternal::EndpointI::connectors;
+    using ::IceInternal::EndpointI::connectors;
 #endif
     
 private:
diff --git a/cpp/test/IceUtil/unicode/Client.cpp b/cpp/test/IceUtil/unicode/Client.cpp
index a8b99a4..6f869df 100644
--- a/cpp/test/IceUtil/unicode/Client.cpp
+++ b/cpp/test/IceUtil/unicode/Client.cpp
@@ -11,6 +11,10 @@
 #include <TestCommon.h>
 #include <fstream>
 
+#ifdef __FreeBSD__
+#   include <unistd.h>
+#endif
+
 using namespace IceUtil;
 using namespace std;
 
diff --git a/cpp/test/Slice/keyword/Client.cpp b/cpp/test/Slice/keyword/Client.cpp
index 5eaf655..a6a12d6 100644
--- a/cpp/test/Slice/keyword/Client.cpp
+++ b/cpp/test/Slice/keyword/Client.cpp
@@ -73,6 +73,9 @@ public:
     virtual void ice_response(Ice::Int)  {}
     virtual void ice_exception(const ::Ice::Exception&) {}
 };
+
+template<typename T>
+void unused(T const &) { }
    
 //
 // This section of the test is present to ensure that the C++ types
@@ -86,6 +89,7 @@ testtypes()
 
     _cpp_and::_cpp_auto b;
     b._cpp_default = 0;
+    unused(b);
 
     _cpp_and::deletePtr c = new _cpp_and::_cpp_delete();
     c->_cpp_else = "";
diff --git a/cpp/test/include/TestCommon.h b/cpp/test/include/TestCommon.h
index cd4993a..03a3093 100644
--- a/cpp/test/include/TestCommon.h
+++ b/cpp/test/include/TestCommon.h
@@ -17,6 +17,22 @@
 #include <stdlib.h>
 #endif
 
+#if defined(__FreeBSD__)
+#  include <sys/types.h>
+#  include <sys/sysctl.h>
+inline bool inFreeBSDJail()
+{
+    int jailed;
+    size_t size = sizeof(jailed);
+    return (sysctlbyname("security.jail.jailed", &jailed, &size, NULL, 0) != -1 || jailed);
+}
+#else
+inline bool inFreeBSDJail()
+{
+    return false;
+}
+#endif
+
 void
 inline testFailed(const char* expr, const char* file, unsigned int line)
 {
