Fix compilation with Boost 1.65.0

Also sync default-compiler-flags.py with NFD

Change-Id: Ib39118567428e8fe2ac73f2b7cbd96fe1a9598b8
Refs: #4259, #4248
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index f946d0d..5cb8d9d 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -7,23 +7,34 @@
                    help='''Compile in debugging mode with minimal optimizations (-O0 or -Og)''')
 
 def configure(conf):
-    cxx = conf.env['CXX_NAME'] # CXX_NAME represents generic name of the compiler
+    conf.start_msg('Checking C++ compiler version')
+
+    cxx = conf.env['CXX_NAME'] # CXX_NAME is the generic name of the compiler
     ccver = tuple(int(i) for i in conf.env['CC_VERSION'])
+    errmsg = ''
+    warnmsg = ''
     if cxx == 'gcc':
         if ccver < (4, 8, 2):
-            conf.fatal('The version of gcc you are using (%s) is too old.\n'
-                       'The minimum supported gcc version is 4.8.2.' %
-                       '.'.join(conf.env['CC_VERSION']))
+            errmsg = ('The version of gcc you are using is too old.\n'
+                      'The minimum supported gcc version is 4.8.2.')
         flags = GccFlags()
     elif cxx == 'clang':
         if ccver < (3, 4, 0):
-            conf.fatal('The version of clang you are using (%s) is too old.\n'
-                       'The minimum supported clang version is 3.4.0.' %
-                       '.'.join(conf.env['CC_VERSION']))
+            errmsg = ('The version of clang you are using is too old.\n'
+                      'The minimum supported clang version is 3.4.0.')
         flags = ClangFlags()
     else:
+        warnmsg = 'Note: %s compiler is unsupported' % cxx
         flags = CompilerFlags()
-        Logs.warn('The code has not yet been tested with %s compiler' % cxx)
+
+    if errmsg:
+        conf.end_msg('.'.join(conf.env['CC_VERSION']), color='RED')
+        conf.fatal(errmsg)
+    elif warnmsg:
+        conf.end_msg('.'.join(conf.env['CC_VERSION']), color='YELLOW')
+        Logs.warn(warnmsg)
+    else:
+        conf.end_msg('.'.join(conf.env['CC_VERSION']))
 
     areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
 
@@ -121,9 +132,9 @@
                               '-Wall',
                               '-Wextra',
                               '-Werror',
-                              '-Wno-unused-parameter',
-                              '-Wno-error=maybe-uninitialized', # Bug #1615
                               '-Wno-error=deprecated-declarations', # Bug #3795
+                              '-Wno-error=maybe-uninitialized', # Bug #1615
+                              '-Wno-unused-parameter',
                               ]
         flags['LINKFLAGS'] += ['-fuse-ld=gold', '-Wl,-O1']
         return flags
@@ -167,24 +178,32 @@
 
     def getDebugFlags(self, conf):
         flags = super(ClangFlags, self).getDebugFlags(conf)
+        flags['CXXFLAGS'] += ['-fcolor-diagnostics',
+                              '-Wextra-semi',
+                              '-Wundefined-func-template',
+                              '-Wno-error=deprecated-register',
+                              '-Wno-error=infinite-recursion', # Bug #3358
+                              '-Wno-error=keyword-macro', # Bug #3235
+                              '-Wno-error=unneeded-internal-declaration', # Bug #1588
+                              '-Wno-unused-local-typedef', # Bugs #2657 and #3209
+                              ]
         version = tuple(int(i) for i in conf.env['CC_VERSION'])
+        if version < (3, 9, 0) or (Utils.unversioned_sys_platform() == 'darwin' and version < (8, 1, 0)):
+            flags['CXXFLAGS'] += ['-Wno-unknown-pragmas']
         if Utils.unversioned_sys_platform() == 'darwin' and version < (7, 0, 0):
             flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
-        flags['CXXFLAGS'] += ['-fcolor-diagnostics',
-                              '-Wno-unused-local-typedef', # Bugs #2657 and #3209
-                              '-Wno-error=unneeded-internal-declaration', # Bug #1588
-                              '-Wno-error=deprecated-register',
-                              '-Wno-error=keyword-macro', # Bug #3235
-                              '-Wno-error=infinite-recursion', # Bug #3358
-                              ]
         return flags
 
     def getOptimizedFlags(self, conf):
         flags = super(ClangFlags, self).getOptimizedFlags(conf)
-        version = tuple(int(i) for i in conf.env['CC_VERSION'])
-        if Utils.unversioned_sys_platform() == 'darwin' and version < (7, 0, 0):
-            flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
         flags['CXXFLAGS'] += ['-fcolor-diagnostics',
+                              '-Wextra-semi',
+                              '-Wundefined-func-template',
                               '-Wno-unused-local-typedef', # Bugs #2657 and #3209
                               ]
+        version = tuple(int(i) for i in conf.env['CC_VERSION'])
+        if version < (3, 9, 0) or (Utils.unversioned_sys_platform() == 'darwin' and version < (8, 1, 0)):
+            flags['CXXFLAGS'] += ['-Wno-unknown-pragmas']
+        if Utils.unversioned_sys_platform() == 'darwin' and version < (7, 0, 0):
+            flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
         return flags
diff --git a/core/common.hpp b/core/common.hpp
index 01a30c4..f74c272 100644
--- a/core/common.hpp
+++ b/core/common.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -40,13 +40,12 @@
 
 #include <cinttypes>
 #include <cstddef>
-
 #include <iostream>
 #include <list>
 #include <map>
 #include <set>
-#include <unordered_map>
-#include <unordered_set>
+#include <stdexcept>
+#include <utility>
 #include <vector>
 
 #include <boost/asio.hpp>
@@ -77,7 +76,6 @@
 namespace signal = util::signal;
 namespace scheduler = util::scheduler;
 
-
 } // namespace ndn
 
 #endif // NDN_TOOLS_CORE_COMMON_HPP
diff --git a/tests/chunks/producer.t.cpp b/tests/chunks/producer.t.cpp
index d3c339f..c19920b 100644
--- a/tests/chunks/producer.t.cpp
+++ b/tests/chunks/producer.t.cpp
@@ -25,13 +25,15 @@
 
 #include "tools/chunks/putchunks/producer.hpp"
 
+#include "tests/test-common.hpp"
+#include "tests/identity-management-fixture.hpp"
+
 #include <ndn-cxx/security/pib/identity.hpp>
 #include <ndn-cxx/security/pib/key.hpp>
 #include <ndn-cxx/util/dummy-client-face.hpp>
-#include <cmath>
 
-#include "tests/test-common.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include <cmath>
+#include <sstream>
 
 namespace ndn {
 namespace chunks {
diff --git a/tools/chunks/catchunks/pipeline-interests-aimd.hpp b/tools/chunks/catchunks/pipeline-interests-aimd.hpp
index ec5bfce..aa19d3f 100644
--- a/tools/chunks/catchunks/pipeline-interests-aimd.hpp
+++ b/tools/chunks/catchunks/pipeline-interests-aimd.hpp
@@ -32,6 +32,7 @@
 #include "pipeline-interests.hpp"
 
 #include <queue>
+#include <unordered_map>
 
 namespace ndn {
 namespace chunks {
diff --git a/tools/dissect/main.cpp b/tools/dissect/main.cpp
index 7232e32..30bf6db 100644
--- a/tools/dissect/main.cpp
+++ b/tools/dissect/main.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California.
+ * Copyright (c) 2014-2017,  Regents of the University of California.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -24,12 +24,14 @@
 #include <boost/program_options/variables_map.hpp>
 #include <boost/program_options/parsers.hpp>
 
+#include <fstream>
+
 namespace po = boost::program_options;
 
 namespace ndn {
 namespace dissect {
 
-void
+static void
 usage(std::ostream& os, const std::string& appName, const po::options_description& options)
 {
   os << "Usage:\n"
@@ -38,7 +40,7 @@
      << options;
 }
 
-int
+static int
 main(int argc, char* argv[])
 {
   po::options_description visibleOptions;
diff --git a/tools/dissect/ndn-dissect.cpp b/tools/dissect/ndn-dissect.cpp
index f37195e..6cd8659 100644
--- a/tools/dissect/ndn-dissect.cpp
+++ b/tools/dissect/ndn-dissect.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California.
+ * Copyright (c) 2014-2017,  Regents of the University of California.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -41,7 +41,6 @@
 #include "ndn-dissect.hpp"
 
 #include <algorithm>
-#include <map>
 
 #include <ndn-cxx/name-component.hpp>
 #include <ndn-cxx/util/indented-stream.hpp>
@@ -49,7 +48,7 @@
 namespace ndn {
 namespace dissect {
 
-std::map<uint32_t, std::string> TLV_DICT = {
+static const std::map<uint32_t, std::string> TLV_DICT = {
   {tlv::Interest                     , "Interest"},
   {tlv::Data                         , "Data"},
   {tlv::Name                         , "Name"},
@@ -82,8 +81,9 @@
 {
   os << type << " (";
 
-  if (TLV_DICT.count(type) != 0) {
-    os << TLV_DICT[type];
+  auto it = TLV_DICT.find(type);
+  if (it != TLV_DICT.end()) {
+    os << it->second;
   }
   else if (type < tlv::AppPrivateBlock1) {
     os << "RESERVED_1";
@@ -97,6 +97,7 @@
   else {
     os << "APP_TAG_3";
   }
+
   os << ")";
 }
 
@@ -110,7 +111,7 @@
     // if (block.type() != tlv::Content && block.type() != tlv::SignatureValue)
     block.parse();
   }
-  catch (tlv::Error& e) {
+  catch (const tlv::Error&) {
     // pass (e.g., leaf block reached)
 
     // @todo: Figure how to deterministically figure out that value is not recursive TLV block
@@ -138,7 +139,7 @@
       Block block = Block::fromStream(is);
       this->printBlock(os, block);
     }
-    catch (std::exception& e) {
+    catch (const std::exception& e) {
       std::cerr << "ERROR: " << e.what() << std::endl;
     }
   }
diff --git a/tools/dissect/ndn-dissect.hpp b/tools/dissect/ndn-dissect.hpp
index a90b845..062d3f0 100644
--- a/tools/dissect/ndn-dissect.hpp
+++ b/tools/dissect/ndn-dissect.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California.
+ * Copyright (c) 2014-2017,  Regents of the University of California.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -17,8 +17,12 @@
  * ndn-tools, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#ifndef NDN_TOOLS_DISSECT_NDN_DISSECT_HPP
+#define NDN_TOOLS_DISSECT_NDN_DISSECT_HPP
+
+#include "core/common.hpp"
+
 #include <ndn-cxx/encoding/block.hpp>
-#include <fstream>
 
 namespace ndn {
 namespace dissect {
@@ -39,3 +43,5 @@
 
 } // namespace dissect
 } // namespace ndn
+
+#endif // NDN_TOOLS_DISSECT_NDN_DISSECT_HPP
diff --git a/tools/dump/main.cpp b/tools/dump/main.cpp
index 2ace7f6..7e23ef9 100644
--- a/tools/dump/main.cpp
+++ b/tools/dump/main.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California.
+ * Copyright (c) 2014-2017,  Regents of the University of California.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -41,6 +41,8 @@
 #include <boost/program_options/variables_map.hpp>
 #include <boost/program_options/parsers.hpp>
 
+#include <sstream>
+
 namespace po = boost::program_options;
 
 namespace boost {
diff --git a/tools/dump/ndndump.cpp b/tools/dump/ndndump.cpp
index 91d6827..e6cfc6a 100644
--- a/tools/dump/ndndump.cpp
+++ b/tools/dump/ndndump.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California.
+ * Copyright (c) 2014-2017,  Regents of the University of California.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -55,6 +55,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include <iomanip>
+#include <sstream>
 
 #include <ndn-cxx/interest.hpp>
 #include <ndn-cxx/data.hpp>
@@ -251,7 +252,8 @@
   //   os << (int) header->ts.tv_sec
   //      << "."
   //      << setfill('0') << setw(6) << (int)header->ts.tv_usec;
-  // } else {
+  // }
+  // else {
   //   tm = localtime(&(header->ts.tv_sec));
   //   os << (int)tm->tm_hour << ":"
   //      << setfill('0') << setw(2) << (int)tm->tm_min<< ":"
diff --git a/tools/peek/ndn-poke.cpp b/tools/peek/ndn-poke.cpp
index 9ef3c53..adfe93e 100644
--- a/tools/peek/ndn-poke.cpp
+++ b/tools/peek/ndn-poke.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -50,6 +50,8 @@
 
 #include "core/version.hpp"
 
+#include <sstream>
+
 namespace ndn {
 namespace peek {
 
@@ -217,7 +219,7 @@
       else
         m_face.processEvents(m_timeout);
     }
-    catch (std::exception& e) {
+    catch (const std::exception& e) {
       std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
       exit(1);
     }
diff --git a/tools/pib/pib-validator.hpp b/tools/pib/pib-validator.hpp
index 8b303f5..0bdf357 100644
--- a/tools/pib/pib-validator.hpp
+++ b/tools/pib/pib-validator.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California.
+ * Copyright (c) 2014-2017,  Regents of the University of California.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -24,21 +24,21 @@
 
 #include "pib-db.hpp"
 #include "key-cache.hpp"
+
 #include <ndn-cxx/security/validator.hpp>
-#include <unordered_map>
 
 namespace ndn {
 namespace pib {
 
-
 /*
  * @brief The validator to verify the command interests to PIB service
  *
- * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base
+ * @sa https://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base
  */
 class PibValidator : public Validator
 {
   struct UserKeyCache;
+
 public:
   explicit
   PibValidator(const PibDb& pibDb,
@@ -47,22 +47,21 @@
   ~PibValidator();
 
 protected:
-  virtual void
+  void
   checkPolicy(const Interest& interest,
               int nSteps,
               const OnInterestValidated& onValidated,
               const OnInterestValidationFailed& onValidationFailed,
-              std::vector<shared_ptr<ValidationRequest>>& nextSteps);
+              std::vector<shared_ptr<ValidationRequest>>& nextSteps) override;
 
-  virtual void
+  void
   checkPolicy(const Data& data,
               int nSteps,
               const OnDataValidated& onValidated,
               const OnDataValidationFailed& onValidationFailed,
-              std::vector<shared_ptr<ValidationRequest>>& nextSteps);
+              std::vector<shared_ptr<ValidationRequest>>& nextSteps) override;
 
 private:
-
   const PibDb& m_db;
 
   bool m_isMgmtReady;
diff --git a/tools/ping/client/ndn-ping.cpp b/tools/ping/client/ndn-ping.cpp
index d94cd0c..19f5bb6 100644
--- a/tools/ping/client/ndn-ping.cpp
+++ b/tools/ping/client/ndn-ping.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Arizona Board of Regents.
+ * Copyright (c) 2014-2017,  Arizona Board of Regents.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -57,7 +57,7 @@
       m_ping.start();
       m_face.processEvents();
     }
-    catch (std::exception& e) {
+    catch (const std::exception& e) {
       m_tracer.onError(e.what());
       return 2;
     }
@@ -102,7 +102,7 @@
 
     m_statisticsCollector.computeStatistics().printSummary(std::cout);
     m_signalSetQuit.async_wait(bind(&Runner::afterQuitSignal, this, _1));
-  };
+  }
 
 private:
   Face m_face;