You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/08/24 07:36:57 UTC

[avro] branch branch-1.11 updated: AVRO-3616: C++ Fix compilation warnings (#1836)

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

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new a053fc026 AVRO-3616: C++ Fix compilation warnings (#1836)
a053fc026 is described below

commit a053fc026392d7675a351c0a6938d2bec892642c
Author: Martin Grigorov <ma...@users.noreply.github.com>
AuthorDate: Wed Aug 24 10:36:23 2022 +0300

    AVRO-3616: C++ Fix compilation warnings (#1836)
    
    * AVRO-3616: [C++]: Fix compilation warnings
    
    Replace <boost/test/included/unit_test_framework.hpp> include with <boost/test/included/unit_test.hpp>
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    * AVRO-3616: [C++]: Fix compilation warnings
    
    Fix the order of constructor parameters
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    * AVRO-3616: Enable -pedantic and -Werror for compiler flags
    
    Those should prevent from introducing new warnings.
    
    -Wextra reports "unused method arguments" and those could not be fixed
    without API break.
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    * AVRO-3616: Use size_t consistently for node->leaves()
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    (cherry picked from commit d336c6c7b91f9f39de2a5e34ae55c1d7c118507b)
---
 lang/c++/CMakeLists.txt                      |  2 +-
 lang/c++/api/AvroTraits.hh                   |  8 ++++----
 lang/c++/api/NodeImpl.hh                     |  4 ++--
 lang/c++/impl/DataFile.cc                    | 10 +++++-----
 lang/c++/impl/Resolver.cc                    |  2 +-
 lang/c++/impl/ValidSchema.cc                 |  4 ++--
 lang/c++/impl/Validator.cc                   |  2 +-
 lang/c++/test/AvrogencppTestReservedWords.cc |  2 +-
 lang/c++/test/AvrogencppTests.cc             |  2 +-
 lang/c++/test/CodecTests.cc                  |  2 +-
 lang/c++/test/CompilerTests.cc               |  2 +-
 lang/c++/test/DataFileTests.cc               |  2 +-
 lang/c++/test/JsonTests.cc                   |  2 +-
 lang/c++/test/LargeSchemaTests.cc            |  2 +-
 lang/c++/test/SchemaTests.cc                 |  2 +-
 lang/c++/test/SpecificTests.cc               |  2 +-
 lang/c++/test/StreamTests.cc                 |  2 +-
 lang/c++/test/buffertest.cc                  |  2 +-
 lang/c++/test/testgentest.cc                 |  2 +-
 lang/c++/test/unittest.cc                    |  2 +-
 20 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index c901437e6..52d6ac8a5 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -64,7 +64,7 @@ if (WIN32 AND NOT CYGWIN AND NOT MSYS)
 endif()
 
 if (CMAKE_COMPILER_IS_GNUCXX)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror")
 if (AVRO_ADD_PROTECTOR_FLAGS)
     set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstack-protector-all -D_GLIBCXX_DEBUG")
     # Unset _GLIBCXX_DEBUG for avrogencpp.cc because using Boost Program Options
diff --git a/lang/c++/api/AvroTraits.hh b/lang/c++/api/AvroTraits.hh
index 7b5a636ec..465470a93 100644
--- a/lang/c++/api/AvroTraits.hh
+++ b/lang/c++/api/AvroTraits.hh
@@ -60,10 +60,10 @@ struct is_defined {
     typedef char no[2];
 
     template<class U>
-    static yes &test(char (*)[sizeof(U)]) { throw 0; };
+    static yes &test(char (*)[sizeof(U)]) { throw 0; }
 
     template<class U>
-    static no &test(...) { throw 0; };
+    static no &test(...) { throw 0; }
 
     static const bool value = sizeof(test<T>(0)) == sizeof(yes);
 };
@@ -82,10 +82,10 @@ struct is_not_defined {
     typedef char no[2];
 
     template<class U>
-    static yes &test(char (*)[sizeof(U)]) { throw 0; };
+    static yes &test(char (*)[sizeof(U)]) { throw 0; }
 
     template<class U>
-    static no &test(...) { throw 0; };
+    static no &test(...) { throw 0; }
 
     static const bool value = sizeof(test<T>(0)) == sizeof(no);
 };
diff --git a/lang/c++/api/NodeImpl.hh b/lang/c++/api/NodeImpl.hh
index bf0e3529b..ef1c1dac9 100644
--- a/lang/c++/api/NodeImpl.hh
+++ b/lang/c++/api/NodeImpl.hh
@@ -544,9 +544,9 @@ NodeImpl<A, B, C, D, E>::printBasicInfo(std::ostream &os) const {
         os << " " << sizeAttribute_.get();
     }
     os << '\n';
-    int count = leaves();
+    size_t count = leaves();
     count = count ? count : names();
-    for (int i = 0; i < count; ++i) {
+    for (size_t i = 0; i < count; ++i) {
         if (C::hasAttribute) {
             os << "name " << nameAt(i) << '\n';
         }
diff --git a/lang/c++/impl/DataFile.cc b/lang/c++/impl/DataFile.cc
index 966eff853..45fdbb649 100644
--- a/lang/c++/impl/DataFile.cc
+++ b/lang/c++/impl/DataFile.cc
@@ -256,14 +256,14 @@ void DataFileWriterBase::setMetadata(const string &key, const string &value) {
     metadata_[key] = v;
 }
 
-DataFileReaderBase::DataFileReaderBase(const char *filename) : filename_(filename), codec_(NULL_CODEC), stream_(fileSeekableInputStream(filename)),
-                                                               decoder_(binaryDecoder()), objectCount_(0), eof_(false), blockStart_(-1),
-                                                               blockEnd_(-1) {
+DataFileReaderBase::DataFileReaderBase(const char *filename) : filename_(filename), stream_(fileSeekableInputStream(filename)),
+                                                               decoder_(binaryDecoder()), objectCount_(0), eof_(false),
+                                                               codec_(NULL_CODEC), blockStart_(-1), blockEnd_(-1) {
     readHeader();
 }
 
-DataFileReaderBase::DataFileReaderBase(std::unique_ptr<InputStream> inputStream) : codec_(NULL_CODEC), stream_(std::move(inputStream)),
-                                                                                   decoder_(binaryDecoder()), objectCount_(0), eof_(false) {
+DataFileReaderBase::DataFileReaderBase(std::unique_ptr<InputStream> inputStream) : stream_(std::move(inputStream)),
+                                                                                   decoder_(binaryDecoder()), objectCount_(0), eof_(false), codec_(NULL_CODEC) {
     readHeader();
 }
 
diff --git a/lang/c++/impl/Resolver.cc b/lang/c++/impl/Resolver.cc
index 919345e8a..d19a04ad7 100644
--- a/lang/c++/impl/Resolver.cc
+++ b/lang/c++/impl/Resolver.cc
@@ -710,8 +710,8 @@ NonUnionToUnionParser::NonUnionToUnionParser(ResolverFactory &factory,
                                              const NodePtr &writer,
                                              const NodePtr &reader,
                                              const CompoundLayout &offsets) : Resolver(),
-                                                                              offset_(offsets.offset()),
                                                                               choice_(0),
+                                                                              offset_(offsets.offset()),
                                                                               choiceOffset_(offsets.at(0).offset()),
                                                                               setFuncOffset_(offsets.at(1).offset()) {
 #ifndef NDEBUG
diff --git a/lang/c++/impl/ValidSchema.cc b/lang/c++/impl/ValidSchema.cc
index 63a3bbee9..1356d8448 100644
--- a/lang/c++/impl/ValidSchema.cc
+++ b/lang/c++/impl/ValidSchema.cc
@@ -69,8 +69,8 @@ static bool validate(const NodePtr &node, SymbolMap &symbolMap) {
     }
 
     node->lock();
-    auto leaves = node->leaves();
-    for (auto i = 0; i < leaves; ++i) {
+    size_t leaves = node->leaves();
+    for (size_t i = 0; i < leaves; ++i) {
         const NodePtr &leaf(node->leafAt(i));
 
         if (!validate(leaf, symbolMap)) {
diff --git a/lang/c++/impl/Validator.cc b/lang/c++/impl/Validator.cc
index 0e5fd8bed..3cd4e9e49 100644
--- a/lang/c++/impl/Validator.cc
+++ b/lang/c++/impl/Validator.cc
@@ -71,7 +71,7 @@ bool Validator::countingSetup() {
 
 void Validator::countingAdvance() {
     if (countingSetup()) {
-        auto index = (compoundStack_.back().pos)++;
+        size_t index = (compoundStack_.back().pos)++;
         const NodePtr &node = compoundStack_.back().node;
 
         if (index < node->leaves()) {
diff --git a/lang/c++/test/AvrogencppTestReservedWords.cc b/lang/c++/test/AvrogencppTestReservedWords.cc
index 7d305fb44..2bee4ab25 100644
--- a/lang/c++/test/AvrogencppTestReservedWords.cc
+++ b/lang/c++/test/AvrogencppTestReservedWords.cc
@@ -19,7 +19,7 @@
 
 #include "Compiler.hh"
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 
 #ifdef min
 #undef min
diff --git a/lang/c++/test/AvrogencppTests.cc b/lang/c++/test/AvrogencppTests.cc
index 2130f818b..144a500a6 100644
--- a/lang/c++/test/AvrogencppTests.cc
+++ b/lang/c++/test/AvrogencppTests.cc
@@ -23,7 +23,7 @@
 #include "union_array_union.hh"
 #include "union_map_union.hh"
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 
 #ifdef min
 #undef min
diff --git a/lang/c++/test/CodecTests.cc b/lang/c++/test/CodecTests.cc
index 7d1141602..27779bb03 100644
--- a/lang/c++/test/CodecTests.cc
+++ b/lang/c++/test/CodecTests.cc
@@ -34,7 +34,7 @@
 
 #include <boost/math/special_functions/fpclassify.hpp>
 #include <boost/random/mersenne_twister.hpp>
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <boost/test/parameterized_test.hpp>
 #include <boost/test/unit_test.hpp>
 
diff --git a/lang/c++/test/CompilerTests.cc b/lang/c++/test/CompilerTests.cc
index e3d4426a3..6fa5344ac 100644
--- a/lang/c++/test/CompilerTests.cc
+++ b/lang/c++/test/CompilerTests.cc
@@ -18,7 +18,7 @@
 
 #include <sstream>
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <boost/test/unit_test.hpp>
 
 #include "Compiler.hh"
diff --git a/lang/c++/test/DataFileTests.cc b/lang/c++/test/DataFileTests.cc
index fec7f316a..a29a6f9c2 100644
--- a/lang/c++/test/DataFileTests.cc
+++ b/lang/c++/test/DataFileTests.cc
@@ -20,7 +20,7 @@
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/uniform_int_distribution.hpp>
 #include <boost/shared_ptr.hpp>
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <boost/test/unit_test.hpp>
 
 #include <chrono>
diff --git a/lang/c++/test/JsonTests.cc b/lang/c++/test/JsonTests.cc
index 3832e6913..da9722f30 100644
--- a/lang/c++/test/JsonTests.cc
+++ b/lang/c++/test/JsonTests.cc
@@ -18,7 +18,7 @@
 
 #include <limits>
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <boost/test/parameterized_test.hpp>
 #include <boost/test/unit_test.hpp>
 
diff --git a/lang/c++/test/LargeSchemaTests.cc b/lang/c++/test/LargeSchemaTests.cc
index a12974c0f..d99e70988 100644
--- a/lang/c++/test/LargeSchemaTests.cc
+++ b/lang/c++/test/LargeSchemaTests.cc
@@ -21,7 +21,7 @@
 #include "ValidSchema.hh"
 #include <fstream>
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <boost/test/parameterized_test.hpp>
 
 void testLargeSchema() {
diff --git a/lang/c++/test/SchemaTests.cc b/lang/c++/test/SchemaTests.cc
index b1260f567..d73b759cf 100755
--- a/lang/c++/test/SchemaTests.cc
+++ b/lang/c++/test/SchemaTests.cc
@@ -20,7 +20,7 @@
 #include "GenericDatum.hh"
 #include "ValidSchema.hh"
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <boost/test/parameterized_test.hpp>
 #include <boost/test/unit_test.hpp>
 
diff --git a/lang/c++/test/SpecificTests.cc b/lang/c++/test/SpecificTests.cc
index e027f9518..72f2897e4 100644
--- a/lang/c++/test/SpecificTests.cc
+++ b/lang/c++/test/SpecificTests.cc
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <boost/test/unit_test.hpp>
 
 #include "Specific.hh"
diff --git a/lang/c++/test/StreamTests.cc b/lang/c++/test/StreamTests.cc
index 262e0600a..7eae5e12a 100644
--- a/lang/c++/test/StreamTests.cc
+++ b/lang/c++/test/StreamTests.cc
@@ -19,7 +19,7 @@
 #include "Exception.hh"
 #include "Stream.hh"
 #include "boost/filesystem.hpp"
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <boost/test/parameterized_test.hpp>
 
 namespace avro {
diff --git a/lang/c++/test/buffertest.cc b/lang/c++/test/buffertest.cc
index 188102859..904f8adbd 100644
--- a/lang/c++/test/buffertest.cc
+++ b/lang/c++/test/buffertest.cc
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 
 #include <boost/bind.hpp>
 
diff --git a/lang/c++/test/testgentest.cc b/lang/c++/test/testgentest.cc
index 3d86329ce..c204dd996 100644
--- a/lang/c++/test/testgentest.cc
+++ b/lang/c++/test/testgentest.cc
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <fstream>
 #include <sstream>
 #include <stdlib.h>
diff --git a/lang/c++/test/unittest.cc b/lang/c++/test/unittest.cc
index 3ed931068..73b92f1f7 100644
--- a/lang/c++/test/unittest.cc
+++ b/lang/c++/test/unittest.cc
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-#include <boost/test/included/unit_test_framework.hpp>
+#include <boost/test/included/unit_test.hpp>
 #include <iostream>
 #include <memory>
 #include <string>