Parcourir la source

[trac899] Initialise member variable before running constructor

The FreeBSD compiler complained that the member variable logger_
could not be constructed because the data type (log4cplus::Logger)
has no default constructor.  It is therefore initialized to point
to the log4cplus root logger (the one that is guaranteed to exist),
even though the LoggerImpl constructor may reset it immediately
afterwards.
Stephen Morris il y a 14 ans
Parent
commit
c24dd6f877
1 fichiers modifiés avec 7 ajouts et 3 suppressions
  1. 7 3
      src/lib/log/logger_impl.cc

+ 7 - 3
src/lib/log/logger_impl.cc

@@ -42,8 +42,12 @@ using namespace std;
 namespace isc {
 namespace log {
 
-// Constructor
-LoggerImpl::LoggerImpl(const string& name)
+// Constructor.  Although it may be immediately reset, logger_ is initialized to
+// the log4cplus root logger; at least one compiler requires that all member
+// variables be constructed before the constructor is run, but log4cplus::Logger
+// (the type of logger_) has no default constructor.
+LoggerImpl::LoggerImpl(const string& name) :
+    logger_(log4cplus::Logger::getRoot())
 {
     // Initialize log4cplus if not already done
     initLog4cplus();
@@ -51,7 +55,7 @@ LoggerImpl::LoggerImpl(const string& name)
     // Are we the root logger?
     if (name == getRootLoggerName()) {
         name_ = name;
-        logger_ = log4cplus::Logger::getRoot();
+        // logger_ already set to log4cplus root logger at this point
 
     } else {
         name_ = getRootLoggerName() + "." + name;