From: Stephen Morris Date: Mon, 12 Dec 2011 14:29:12 +0000 (+0000) Subject: [1470] Remove "this" from initializer lists X-Git-Tag: perftcpdns_before_epoll~5^2~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c254f7fcb4fac6b47cc880221aa5d28a0772b641;p=thirdparty%2Fkea.git [1470] Remove "this" from initializer lists Some compilers warn if "this" is referred to in a constructor initialization list. This change replaces such initializations with an assignment within the constructor body. --- diff --git a/src/bin/auth/auth_srv.cc b/src/bin/auth/auth_srv.cc index caf69b9a7c..92eec6f12d 100644 --- a/src/bin/auth/auth_srv.cc +++ b/src/bin/auth/auth_srv.cc @@ -228,12 +228,13 @@ private: AuthSrv* server_; }; -AuthSrv::AuthSrv(const bool use_cache, AbstractXfroutClient& xfrout_client) : - impl_(new AuthSrvImpl(use_cache, xfrout_client)), - checkin_(new ConfigChecker(this)), - dns_lookup_(new MessageLookup(this)), - dns_answer_(new MessageAnswer(this)) -{} +AuthSrv::AuthSrv(const bool use_cache, AbstractXfroutClient& xfrout_client) +{ + impl_ = new AuthSrvImpl(use_cache, xfrout_client); + checkin_ = new ConfigChecker(this); + dns_lookup_ = new MessageLookup(this); + dns_answer_ = new MessageAnswer(this); +} void AuthSrv::stop() { diff --git a/src/bin/resolver/resolver.cc b/src/bin/resolver/resolver.cc index bb1eb3bbe8..473a9c234e 100644 --- a/src/bin/resolver/resolver.cc +++ b/src/bin/resolver/resolver.cc @@ -354,13 +354,19 @@ private: Resolver::Resolver() : impl_(new ResolverImpl()), dnss_(NULL), - checkin_(new ConfigCheck(this)), - dns_lookup_(new MessageLookup(this)), + checkin_(NULL), + dns_lookup_(NULL), dns_answer_(new MessageAnswer), nsas_(NULL), cache_(NULL), configured_(false) -{} +{ + // Operations referring to "this" must be done in the constructor body + // (some compilers will issue warnings if "this" is referred to in the + // initialization list). + checkin_ = new ConfigCheck(this); + dns_lookup_ = new MessageLookup(this); +} Resolver::~Resolver() { delete impl_; diff --git a/src/lib/asiodns/dns_lookup.h b/src/lib/asiodns/dns_lookup.h index 40290e4e71..5dc84ac34e 100644 --- a/src/lib/asiodns/dns_lookup.h +++ b/src/lib/asiodns/dns_lookup.h @@ -51,7 +51,9 @@ protected: /// /// This is intentionally defined as \c protected as this base class /// should never be instantiated (except as part of a derived class). - DNSLookup() : self_(this) {} + DNSLookup() { + self_ = this; + } public: /// \brief The destructor virtual ~DNSLookup() {} diff --git a/src/lib/asiodns/dns_server.h b/src/lib/asiodns/dns_server.h index f23586062c..d3a8528da8 100644 --- a/src/lib/asiodns/dns_server.h +++ b/src/lib/asiodns/dns_server.h @@ -53,7 +53,9 @@ protected: /// This is intentionally defined as \c protected, as this base class /// should never be instantiated except as part of a derived class. //@{ - DNSServer() : self_(this) {} + DNSServer() { + self_ = this; + } public: /// \brief The destructor virtual ~DNSServer() {} diff --git a/src/lib/asiolink/simple_callback.h b/src/lib/asiolink/simple_callback.h index 92093ec594..a297a1d621 100644 --- a/src/lib/asiolink/simple_callback.h +++ b/src/lib/asiolink/simple_callback.h @@ -49,7 +49,9 @@ protected: /// /// This is intentionally defined as \c protected as this base class /// should never be instantiated (except as part of a derived class). - SimpleCallback() : self_(this) {} + SimpleCallback() { + self_ = this; + } public: /// \brief The destructor virtual ~SimpleCallback() {} diff --git a/src/lib/datasrc/rbtree.h b/src/lib/datasrc/rbtree.h index b6c098a989..4757a455e5 100644 --- a/src/lib/datasrc/rbtree.h +++ b/src/lib/datasrc/rbtree.h @@ -295,15 +295,20 @@ private: // This is only to support NULL nodes. template RBNode::RBNode() : - parent_(this), - left_(this), - right_(this), + parent_(NULL), + left_(NULL), + right_(NULL), color_(BLACK), // dummy name, the value doesn't matter: name_(isc::dns::Name::ROOT_NAME()), - down_(this), + down_(NULL), flags_(0) { + // Some compilers object to use of "this" in initializer lists. + parent_ = this; + left_ = this; + right_ = this; + down_ = this; } template diff --git a/src/lib/resolve/recursive_query.cc b/src/lib/resolve/recursive_query.cc index 1855f7ae9b..55f473e1ce 100644 --- a/src/lib/resolve/recursive_query.cc +++ b/src/lib/resolve/recursive_query.cc @@ -676,11 +676,14 @@ public: nsas_(nsas), cache_(cache), cur_zone_("."), - nsas_callback_(new ResolverNSASCallback(this)), + nsas_callback_(), nsas_callback_out_(false), outstanding_events_(0), rtt_recorder_(recorder) { + // Set here to avoid using "this" in initializer list. + nsas_callback_.reset(new ResolverNSASCallback(this)); + // Setup the timer to stop trying (lookup_timeout) if (lookup_timeout >= 0) { lookup_timer.expires_from_now(