This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 22e279184af0855a56790cca1a8599ff5ea5f04b
Author: Alan M. Carroll <[email protected]>
AuthorDate: Tue Mar 3 16:10:18 2020 -0600

    Fix warnings - not actually enabled by CMake, fixed that and the warnings.
---
 swoc++/CMakeLists.txt               |  3 ++-
 swoc++/include/swoc/ArenaWriter.h   |  2 +-
 swoc++/include/swoc/DiscreteRange.h |  2 +-
 swoc++/include/swoc/Lexicon.h       |  3 +--
 swoc++/include/swoc/bwf_base.h      |  4 ++--
 swoc++/include/swoc/swoc_ip.h       |  8 ++++----
 swoc++/src/bw_ip_format.cc          | 21 ---------------------
 swoc++/src/swoc_ip.cc               | 13 +++++++------
 unit_tests/CMakeLists.txt           |  1 +
 unit_tests/ex_TextView.cc           |  2 +-
 unit_tests/ex_bw_format.cc          |  1 -
 unit_tests/ex_ipspace_properties.cc |  3 ++-
 unit_tests/test_BufferWriter.cc     |  4 ++--
 unit_tests/test_IntrusiveDList.cc   |  5 -----
 unit_tests/test_Lexicon.cc          |  2 +-
 unit_tests/test_MemArena.cc         |  2 +-
 unit_tests/test_ip.cc               |  2 +-
 17 files changed, 27 insertions(+), 51 deletions(-)

diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index cbe96df..a836c7e 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -45,7 +45,8 @@ set(CC_FILES
     )
 
 add_library(swoc++ STATIC ${CC_FILES})
-add_compile_options(-Wall -Wextra -Werror -Wno-ignored-qualifiers 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
+#add_compile_options(-Wall -Wextra -Werror -Wno-unused-parameter 
-Wno-format-truncation -Wno-stringop-overflow -Wno-invalid-offsetof)
+target_compile_options(swoc++ PRIVATE -Wall -Wextra -Werror 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
 
 # Not quite sure how this works, but I think it generates one of two paths 
depending on the context.
 # That is, the generator functions return non-empty strings only in the 
corresponding context.
diff --git a/swoc++/include/swoc/ArenaWriter.h 
b/swoc++/include/swoc/ArenaWriter.h
index 2c41150..a09c573 100644
--- a/swoc++/include/swoc/ArenaWriter.h
+++ b/swoc++/include/swoc/ArenaWriter.h
@@ -59,6 +59,6 @@ protected:
   void realloc(size_t n);
 };
 
-inline swoc::ArenaWriter::ArenaWriter(swoc::MemArena &arena) : _arena(arena), 
super_type(arena.remnant()) {}
+inline swoc::ArenaWriter::ArenaWriter(swoc::MemArena &arena) : 
super_type(arena.remnant()), _arena(arena) {}
 
 } // namespace swoc
diff --git a/swoc++/include/swoc/DiscreteRange.h 
b/swoc++/include/swoc/DiscreteRange.h
index f4dc4d9..967460b 100644
--- a/swoc++/include/swoc/DiscreteRange.h
+++ b/swoc++/include/swoc/DiscreteRange.h
@@ -594,9 +594,9 @@ protected:
     using super_type = detail::RBNode; ///< Parent class.
     friend class DiscreteSpace;
 
-    PAYLOAD _payload{}; ///< Default constructor, should zero init if @c 
PAYLOAD is a pointer.
     range_type _range;  ///< Range covered by this node.
     range_type _hull;   ///< Range covered by subtree rooted at this node.
+    PAYLOAD _payload{}; ///< Default constructor, should zero init if @c 
PAYLOAD is a pointer.
 
   public:
     /// Linkage for @c IntrusiveDList.
diff --git a/swoc++/include/swoc/Lexicon.h b/swoc++/include/swoc/Lexicon.h
index cb782f5..7317f86 100644
--- a/swoc++/include/swoc/Lexicon.h
+++ b/swoc++/include/swoc/Lexicon.h
@@ -47,8 +47,7 @@ namespace detail
   std::string
   what(std::string_view const &fmt, Args &&... args) {
     std::string zret;
-    swoc::bwprint_v(zret, fmt, std::forward_as_tuple(args...));
-    return std::move(zret);
+    return swoc::bwprint_v(zret, fmt, std::forward_as_tuple(args...));
   }
 } // namespace detail
 
diff --git a/swoc++/include/swoc/bwf_base.h b/swoc++/include/swoc/bwf_base.h
index a8aa874..af894af 100644
--- a/swoc++/include/swoc/bwf_base.h
+++ b/swoc++/include/swoc/bwf_base.h
@@ -376,7 +376,7 @@ namespace bwf
       }
 
     protected:
-      Binding(ContextNames const &names, context_type &ctx) : _names(names), 
_ctx(ctx) {}
+      Binding(ContextNames const &names, context_type &ctx) : _ctx(ctx), 
_names(names) {}
 
       context_type &_ctx;         ///< Context for generators.
       ContextNames const &_names; ///< Base set of names.
@@ -846,7 +846,7 @@ BufferWriter::print_nfv(Binding &&names, Extractor &&ex, 
bwf::ArgPack const &arg
   // via the specifier.
   using spec_type =
     typename 
std::remove_reference<decltype(bwf::extractor_spec_type(&std::remove_reference<Extractor>::type::operator()))>::type;
-  size_t N    = args.count();
+  int N    = args.count();
   int arg_idx = 0; // the next argument index to be processed.
 
   // Parser is required to return @c false if there's no more data, @c true if 
something was parsed.
diff --git a/swoc++/include/swoc/swoc_ip.h b/swoc++/include/swoc/swoc_ip.h
index 85c7d8a..59dce88 100644
--- a/swoc++/include/swoc/swoc_ip.h
+++ b/swoc++/include/swoc/swoc_ip.h
@@ -523,13 +523,13 @@ public:
   explicit IPAddr(in_addr_t addr);
 
   /// Construct using an IPv4 @a addr
-  IPAddr(IP4Addr const& addr) : _family(AF_INET), _addr{addr} {}
+  IPAddr(IP4Addr const& addr) : _addr{addr}, _family(AF_INET) {}
 
   /// Construct using IPv6 @a addr.
   explicit IPAddr(in6_addr const& addr);
 
   /// construct using an IPv6 @a addr
-  IPAddr(IP6Addr const& addr) : _family(AF_INET6), _addr{addr} {}
+  IPAddr(IP6Addr const& addr) : _addr{addr}, _family(AF_INET6) {}
 
   /// Construct from @c sockaddr.
   explicit IPAddr(sockaddr const *addr);
@@ -1788,9 +1788,9 @@ auto IPSpace<PAYLOAD>::iterator::operator--() -> 
self_type& {
 // @c constexpr constructor is required to initialize _something_, it can't be 
completely uninitializing.
 inline constexpr IPAddr::raw_addr_type::raw_addr_type() : _ip4(INADDR_ANY) {}
 
-inline IPAddr::IPAddr(in_addr_t addr) : _family(AF_INET), _addr(addr) {}
+inline IPAddr::IPAddr(in_addr_t addr) : _addr(addr), _family(AF_INET) {}
 
-inline IPAddr::IPAddr(in6_addr const& addr) : _family(AF_INET6), _addr(addr) {}
+inline IPAddr::IPAddr(in6_addr const& addr) :  _addr(addr), _family(AF_INET6) 
{}
 
 inline IPAddr::IPAddr(sockaddr const *addr) {
   this->assign(addr);
diff --git a/swoc++/src/bw_ip_format.cc b/swoc++/src/bw_ip_format.cc
index 9da2a77..8c8ecdc 100644
--- a/swoc++/src/bw_ip_format.cc
+++ b/swoc++/src/bw_ip_format.cc
@@ -23,27 +23,6 @@
 
 using namespace swoc::literals;
 
-namespace
-{
-std::string_view
-family_name(sa_family_t family)
-{
-  switch (family) {
-  case AF_INET:
-    return "ipv4"_sv;
-  case AF_INET6:
-    return "ipv6"_sv;
-  case AF_UNIX:
-    return "unix"_sv;
-  case AF_UNSPEC:
-    return "unspec"_sv;
-  default:
-    return "unknown"_sv;
-  }
-}
-
-} // namespace
-
 namespace swoc
 {
 using bwf::Spec;
diff --git a/swoc++/src/swoc_ip.cc b/swoc++/src/swoc_ip.cc
index 59075a6..f358665 100644
--- a/swoc++/src/swoc_ip.cc
+++ b/swoc++/src/swoc_ip.cc
@@ -265,7 +265,7 @@ IP4Addr::load(std::string_view const&text) {
   while (n > 0 && !src.empty()) {
     TextView token{src.take_prefix_at('.')};
     auto x = svto_radix<10>(token);
-    if (token.empty() && 0 <= x && x <= std::numeric_limits<uint8_t>::max()) {
+    if (token.empty() && x <= std::numeric_limits<uint8_t>::max()) {
       octet[--n] = x;
     } else {
       break;
@@ -372,7 +372,7 @@ IP6Addr::load(std::string_view const&str) {
 
   // Sadly the empty quads can't be done in line because it's not possible to 
know the correct index
   // of the next present quad until the entire address has been parsed.
-  while (n < N_QUADS && !src.empty()) {
+  while (n < static_cast<int>(N_QUADS) && !src.empty()) {
     TextView token{src.take_prefix_at(':')};
     if (token.empty()) {
       if (empty_idx >= 0) { // two instances of "::", fail.
@@ -392,9 +392,9 @@ IP6Addr::load(std::string_view const&str) {
 
   // Handle empty quads - invalid if empty and still had a full set of quads
   if (empty_idx >= 0) {
-    if (n < N_QUADS) {
-      auto nil_idx = N_QUADS - (n - empty_idx);
-      auto delta = N_QUADS - n;
+    if (n < static_cast<int>(N_QUADS)) {
+      int nil_idx = N_QUADS - (n - empty_idx);
+      int delta = N_QUADS - n;
       for (int k = N_QUADS - 1; k >= empty_idx; --k) {
         quad[QUAD_IDX[k]] = (k >= nil_idx ? quad[QUAD_IDX[k - delta]] : 0);
       }
@@ -783,7 +783,8 @@ void IP4Range::NetSource::search_wider() {
 
 void IP4Range::NetSource::search_narrower() {
   while (! this->is_valid(_mask)) {
-    _mask._addr = (_mask._addr >>= 1) | (1<<(IP4Addr::WIDTH-1));
+    _mask._addr >>= 1;
+    _mask._addr |= 1<<(IP4Addr::WIDTH-1); // put top bit back.
     ++_cidr;
   }
 }
diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt
index 39de7a7..88f949a 100644
--- a/unit_tests/CMakeLists.txt
+++ b/unit_tests/CMakeLists.txt
@@ -28,4 +28,5 @@ add_executable(test_libswoc
 
 target_link_libraries(test_libswoc PUBLIC swoc++)
 set_target_properties(test_libswoc PROPERTIES CLANG_FORMAT_DIRS 
${CMAKE_CURRENT_SOURCE_DIR})
+target_compile_options(test_libswoc PRIVATE -Wall -Wextra -Werror 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
 #add_definitions(-DVERBOSE_EXAMPLE_OUTPUT=1)
diff --git a/unit_tests/ex_TextView.cc b/unit_tests/ex_TextView.cc
index b6b3b25..a44853f 100644
--- a/unit_tests/ex_TextView.cc
+++ b/unit_tests/ex_TextView.cc
@@ -282,7 +282,7 @@ TEST_CASE("TextView parsing", 
"[libswoc][example][text][parsing]") {
     while (dc_txt) {
       auto key   = dc_txt.take_prefix_at(',');
       auto value = key.take_suffix_at('=');
-      auto n = swoc::svtou(value, &parsed);
+      [[maybe_unused]] auto n = swoc::svtou(value, &parsed);
       // Each element must be one of the known tags, followed by '=' and an 
integer.
       REQUIRE(parsed == value); // value integer.
       REQUIRE(DC_TAGS.find(key) != DC_TAGS.end());
diff --git a/unit_tests/ex_bw_format.cc b/unit_tests/ex_bw_format.cc
index 30bc007..024ef77 100644
--- a/unit_tests/ex_bw_format.cc
+++ b/unit_tests/ex_bw_format.cc
@@ -229,7 +229,6 @@ TEST_CASE("BufferWriter Context 2", 
"[bufferwriter][example][context]")
   // Override the name lookup to handle structured names.
   class CookieBinding : public swoc::bwf::ContextNames<ExContext const>
   {
-    using self_type  = CookieBinding;
     using super_type = swoc::bwf::ContextNames<ExContext const>;
 
   public:
diff --git a/unit_tests/ex_ipspace_properties.cc 
b/unit_tests/ex_ipspace_properties.cc
index c992933..9cad01a 100644
--- a/unit_tests/ex_ipspace_properties.cc
+++ b/unit_tests/ex_ipspace_properties.cc
@@ -571,7 +571,7 @@ TEST_CASE("IPSpace properties", 
"[libswoc][ip][ex][properties]") {
   auto owner = table.add_column(std::make_unique<EnumProperty>("owner"));
   auto colo = table.add_column(std::make_unique<EnumProperty>("colo"));
   auto flags = 
table.add_column(std::make_unique<FlagGroupProperty>("flags"_tv, flag_names));
-  auto description = 
table.add_column(std::make_unique<StringProperty>("Description"));
+  [[maybe_unused]] auto description = 
table.add_column(std::make_unique<StringProperty>("Description"));
 
   TextView src = R"(10.1.1.0/24,asf,cmi,prod;internal,"ASF core net"
 192.168.28.0/25,asf,ind,prod,"Indy Net"
@@ -585,6 +585,7 @@ TEST_CASE("IPSpace properties", 
"[libswoc][ip][ex][properties]") {
   CHECK(true == flags->is_set(*row, 0));
   CHECK(false == flags->is_set(*row, 1));
   CHECK(true == flags->is_set(*row, 2));
+  CHECK("asf"_tv == (*owner)(*row));
 
   row = table.find(IPAddr{"192.168.28.131"});
   REQUIRE(row != nullptr);
diff --git a/unit_tests/test_BufferWriter.cc b/unit_tests/test_BufferWriter.cc
index 8b8d0df..6cb4487 100644
--- a/unit_tests/test_BufferWriter.cc
+++ b/unit_tests/test_BufferWriter.cc
@@ -334,7 +334,7 @@ TEST_CASE("ArenaWriter write", "[BW][ArenaWriter]")
   swoc::TextView tv = span.view();
   try {
     for (char c = 'a'; c <= 'z'; ++c) {
-      for (int i = 0; i < buffer.size(); ++i) {
+      for (size_t i = 0; i < buffer.size(); ++i) {
         if (c != *tv++) {
           throw std::exception{};
         }
@@ -374,7 +374,7 @@ TEST_CASE("ArenaWriter print", "[BW][ArenaWriter]")
   swoc::TextView tv = span.view();
   try {
     for (char c = 'a'; c <= 'z'; ++c) {
-      for (int i = 0; i < buffer.size(); ++i) {
+      for (size_t i = 0; i < buffer.size(); ++i) {
         if (c != *tv++) {
           throw std::exception{};
         }
diff --git a/unit_tests/test_IntrusiveDList.cc 
b/unit_tests/test_IntrusiveDList.cc
index 3c0c72a..17b5bfd 100644
--- a/unit_tests/test_IntrusiveDList.cc
+++ b/unit_tests/test_IntrusiveDList.cc
@@ -129,9 +129,4 @@ TEST_CASE("IntrusiveDList", "[libswoc][IntrusiveDList]")
   list.insert_before(list.end(), new Thing("trailer"));
   REQUIRE(list.count() == 4);
   REQUIRE(list.tail()->_payload == "trailer");
-
-  for ( auto const& elt : list) {
-
-  }
-
 }
diff --git a/unit_tests/test_Lexicon.cc b/unit_tests/test_Lexicon.cc
index db4bdde..443763d 100644
--- a/unit_tests/test_Lexicon.cc
+++ b/unit_tests/test_Lexicon.cc
@@ -75,7 +75,7 @@ TEST_CASE("Lexicon Example", "[libts][Lexicon]")
            {Radio::DELTA, {"Delta"}}});
 
   // test structured binding for iteration.
-  for (auto const &[key, name] : lex) {
+  for ([[maybe_unused]] auto const &[key, name] : lex) {
   }
 };
 
diff --git a/unit_tests/test_MemArena.cc b/unit_tests/test_MemArena.cc
index a3d6ace..59774ef 100644
--- a/unit_tests/test_MemArena.cc
+++ b/unit_tests/test_MemArena.cc
@@ -368,7 +368,7 @@ TEST_CASE("FixedArena", "[libswoc][FixedArena]") {
   MemArena arena;
   FixedArena<Thing> fa{arena};
 
-  Thing * one = fa.make();
+  [[maybe_unused]] Thing * one = fa.make();
   Thing * two = fa.make();
   two->x = 17;
   two->name = "Bob";
diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc
index 0d4b683..b879ce6 100644
--- a/unit_tests/test_ip.cc
+++ b/unit_tests/test_ip.cc
@@ -550,7 +550,7 @@ TEST_CASE("IP Space Int", "[libswoc][ip][ipspace]") {
     lhs |= rhs;
     return true;
   };
-  unsigned *payload;
+
   swoc::IP4Range r_1{"1.1.1.0-1.1.1.9"};
   swoc::IP4Range r_2{"1.1.2.0-1.1.2.97"};
   swoc::IP4Range r_3{"1.1.0.0-1.2.0.0"};

Reply via email to