Skip to content

Commit

Permalink
AVRO-3616: C++ Fix compilation warnings (#1836)
Browse files Browse the repository at this point in the history
* 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 <mgrigorov@apache.org>

* AVRO-3616: [C++]: Fix compilation warnings

Fix the order of constructor parameters

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@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 <mgrigorov@apache.org>

* AVRO-3616: Use size_t consistently for node->leaves()

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
  • Loading branch information
martin-g committed Aug 24, 2022
1 parent d3ecee9 commit d336c6c
Show file tree
Hide file tree
Showing 20 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lang/c++/CMakeLists.txt
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lang/c++/api/AvroTraits.hh
Expand Up @@ -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);
};
Expand All @@ -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);
};
Expand Down
4 changes: 2 additions & 2 deletions lang/c++/api/NodeImpl.hh
Expand Up @@ -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';
}
Expand Down
10 changes: 5 additions & 5 deletions lang/c++/impl/DataFile.cc
Expand Up @@ -259,14 +259,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();
}

Expand Down
2 changes: 1 addition & 1 deletion lang/c++/impl/Resolver.cc
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lang/c++/impl/ValidSchema.cc
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/impl/Validator.cc
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/AvrogencppTestReservedWords.cc
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/AvrogencppTests.cc
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/CodecTests.cc
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/CompilerTests.cc
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/DataFileTests.cc
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/JsonTests.cc
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/LargeSchemaTests.cc
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/SchemaTests.cc
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/SpecificTests.cc
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/StreamTests.cc
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/buffertest.cc
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/testgentest.cc
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion lang/c++/test/unittest.cc
Expand Up @@ -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>
Expand Down

0 comments on commit d336c6c

Please sign in to comment.