Skip to content

Commit

Permalink
C++: Turn on additional compiler warnings (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jun 12, 2024
1 parent 76abc73 commit 1d1537f
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 73 deletions.
2 changes: 1 addition & 1 deletion lang/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
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 -pedantic -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -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
4 changes: 2 additions & 2 deletions lang/c++/README
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ INSTRUCTIONS

Pre-requisites:

To compile requires boost headers, and the boost regex library. Optionally, it requires Snappy compression library. If Snappy is available, it builds support for Snappy compression and skips it otherwise. (Please see your OS-specific instructions on how to install Boost and Snappy for your OS).
To compile requires boost headers, the boost regex library and the fmt library. Optionally, it requires Snappy compression library. If Snappy is available, it builds support for Snappy compression and skips it otherwise. (Please see your OS-specific instructions on how to install Boost and Snappy for your OS).

To build one requires cmake 2.6 or later.
To build one requires cmake 3.5 or later and a compiler which supports at least C++17.

To generate a Makefile under Unix, MacOS (using GNU) or Cygwin use:

Expand Down
4 changes: 2 additions & 2 deletions lang/c++/api/NodeConcepts.hh
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ private:
template<typename T>
struct NameIndexConcept {

bool lookup(const std::string &name, size_t &index) const {
bool lookup(const std::string &, size_t &) const {
throw Exception("Name index does not exist");
}

bool add(const ::std::string &name, size_t) {
bool add(const ::std::string &, size_t) {
throw Exception("Name index does not exist");
}
};
Expand Down
6 changes: 3 additions & 3 deletions lang/c++/api/Validator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace avro {

class AVRO_DECL NullValidator : private boost::noncopyable {
public:
explicit NullValidator(const ValidSchema &schema) {}
explicit NullValidator(const ValidSchema &) {}
NullValidator() = default;

void setCount(int64_t) {}
Expand All @@ -49,11 +49,11 @@ public:
return 0;
}

static bool getCurrentRecordName(std::string &name) {
static bool getCurrentRecordName(std::string &) {
return true;
}

static bool getNextFieldName(std::string &name) {
static bool getNextFieldName(std::string &) {
return true;
}

Expand Down
18 changes: 11 additions & 7 deletions lang/c++/impl/Compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ static Field makeField(const Entity &e, SymbolTable &st, const string &ns) {
const Object &m = e.objectValue();
string n = getStringField(e, m, "name");
vector<string> aliases;
if (containsField(m, "aliases")) {
for (const auto &alias : getArrayField(e, m, "aliases")) {
string aliasesName = "aliases";
if (containsField(m, aliasesName)) {
for (const auto &alias : getArrayField(e, m, aliasesName)) {
aliases.emplace_back(alias.stringValue());
}
}
Expand All @@ -313,7 +314,8 @@ static NodePtr makeRecordNode(const Entity &e, const Name &name,
concepts::MultiAttribute<NodePtr> fieldValues;
concepts::MultiAttribute<CustomAttributes> customAttributes;
vector<GenericDatum> defaultValues;
for (const auto &it : getArrayField(e, m, "fields")) {
string fields = "fields";
for (const auto &it : getArrayField(e, m, fields)) {
Field f = makeField(it, st, ns);
fieldNames.add(f.name);
fieldAliases.push_back(f.aliases);
Expand Down Expand Up @@ -375,7 +377,8 @@ static LogicalType makeLogicalType(const Entity &e, const Object &m) {

static NodePtr makeEnumNode(const Entity &e,
const Name &name, const Object &m) {
const Array &v = getArrayField(e, m, "symbols");
string symbolsName = "symbols";
const Array &v = getArrayField(e, m, symbolsName);
concepts::MultiAttribute<string> symbols;
for (const auto &it : v) {
if (it.type() != json::EntityType::String) {
Expand Down Expand Up @@ -447,8 +450,9 @@ static Name getName(const Entity &e, const Object &m, const string &ns) {
}
}

if (containsField(m, "aliases")) {
for (const auto &alias : getArrayField(e, m, "aliases")) {
std::string aliases = "aliases";
if (containsField(m, aliases)) {
for (const auto &alias : getArrayField(e, m, aliases)) {
result.addAlias(alias.stringValue());
}
}
Expand Down Expand Up @@ -502,7 +506,7 @@ static NodePtr makeNode(const Entity &e, const Object &m,
throw Exception("Unknown type definition: %1%", e.toString());
}

static NodePtr makeNode(const Entity &e, const Array &m,
static NodePtr makeNode(const Entity &, const Array &m,
SymbolTable &st, const string &ns) {
concepts::MultiAttribute<NodePtr> mm;
for (const auto &it : m) {
Expand Down
10 changes: 5 additions & 5 deletions lang/c++/impl/NodeImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ NodePrimitive::resolve(const Node &reader) const {
return RESOLVE_PROMOTABLE_TO_LONG;
}

// fall-through intentional
[[fallthrough]];

case AVRO_LONG:

if (reader.type() == AVRO_FLOAT) {
return RESOLVE_PROMOTABLE_TO_FLOAT;
}

// fall-through intentional
[[fallthrough]];

case AVRO_FLOAT:

Expand Down Expand Up @@ -334,7 +334,7 @@ void NodeRecord::printJson(std::ostream &os, size_t depth) const {
}

void NodePrimitive::printDefaultToJson(const GenericDatum &g, std::ostream &os,
size_t depth) const {
size_t) const {
assert(isPrimitive(g.type()));

switch (g.type()) {
Expand Down Expand Up @@ -375,13 +375,13 @@ void NodePrimitive::printDefaultToJson(const GenericDatum &g, std::ostream &os,
}

void NodeEnum::printDefaultToJson(const GenericDatum &g, std::ostream &os,
size_t depth) const {
size_t) const {
assert(g.type() == AVRO_ENUM);
os << "\"" << g.value<GenericEnum>().symbol() << "\"";
}

void NodeFixed::printDefaultToJson(const GenericDatum &g, std::ostream &os,
size_t depth) const {
size_t) const {
assert(g.type() == AVRO_FIXED);
// ex: "\uOOff"
// Convert to a string
Expand Down
24 changes: 12 additions & 12 deletions lang/c++/impl/Resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PrimitiveSkipper : public Resolver {
public:
PrimitiveSkipper() : Resolver() {}

void parse(Reader &reader, uint8_t *address) const final {
void parse(Reader &reader, uint8_t *) const final {
T val;
reader.readValue(val);
DEBUG_OUT("Skipping " << val);
Expand Down Expand Up @@ -93,7 +93,7 @@ class PrimitivePromoter : public Resolver {
DEBUG_OUT("Promoting " << val);
}

void parseIt(Reader &reader, uint8_t *, const std::false_type &) const {}
void parseIt(Reader &, uint8_t *, const std::false_type &) const {}

template<typename T>
void parseIt(Reader &reader, uint8_t *address) const {
Expand All @@ -108,7 +108,7 @@ class PrimitiveSkipper<std::vector<uint8_t>> : public Resolver {
public:
PrimitiveSkipper() : Resolver() {}

void parse(Reader &reader, uint8_t *address) const final {
void parse(Reader &reader, uint8_t *) const final {
std::vector<uint8_t> val;
reader.readBytes(val);
DEBUG_OUT("Skipping bytes");
Expand Down Expand Up @@ -276,9 +276,9 @@ class ArrayParser : public Resolver {

class EnumSkipper : public Resolver {
public:
EnumSkipper(ResolverFactory &factory, const NodePtr &writer) : Resolver() {}
EnumSkipper(ResolverFactory &, const NodePtr &) : Resolver() {}

void parse(Reader &reader, uint8_t *address) const final {
void parse(Reader &reader, uint8_t *) const final {
int64_t val = reader.readEnum();
DEBUG_OUT("Skipping enum" << val);
}
Expand All @@ -290,9 +290,9 @@ class EnumParser : public Resolver {
VAL
};

EnumParser(ResolverFactory &factory, const NodePtr &writer, const NodePtr &reader, const CompoundLayout &offsets) : Resolver(),
offset_(offsets.at(0).offset()),
readerSize_(reader->names()) {
EnumParser(ResolverFactory &, const NodePtr &writer, const NodePtr &reader, const CompoundLayout &offsets) : Resolver(),
offset_(offsets.at(0).offset()),
readerSize_(reader->names()) {
const size_t writerSize = writer->names();

mapping_.reserve(writerSize);
Expand Down Expand Up @@ -413,11 +413,11 @@ class NonUnionToUnionParser : public Resolver {

class FixedSkipper : public Resolver {
public:
FixedSkipper(ResolverFactory &factory, const NodePtr &writer) : Resolver() {
FixedSkipper(ResolverFactory &, const NodePtr &writer) : Resolver() {
size_ = writer->fixedSize();
}

void parse(Reader &reader, uint8_t *address) const final {
void parse(Reader &reader, uint8_t *) const final {
DEBUG_OUT("Skipping fixed");
std::unique_ptr<uint8_t[]> val(new uint8_t[size_]);
reader.readFixed(&val[0], size_);
Expand All @@ -429,7 +429,7 @@ class FixedSkipper : public Resolver {

class FixedParser : public Resolver {
public:
FixedParser(ResolverFactory &factory, const NodePtr &writer, const NodePtr &reader, const CompoundLayout &offsets) : Resolver() {
FixedParser(ResolverFactory &, const NodePtr &writer, const NodePtr &, const CompoundLayout &offsets) : Resolver() {
size_ = writer->fixedSize();
offset_ = offsets.at(0).offset();
}
Expand All @@ -449,7 +449,7 @@ class ResolverFactory : private boost::noncopyable {

template<typename T>
unique_ptr<Resolver>
constructPrimitiveSkipper(const NodePtr &writer) {
constructPrimitiveSkipper(const NodePtr &) {
return unique_ptr<Resolver>(new PrimitiveSkipper<T>());
}

Expand Down
2 changes: 1 addition & 1 deletion lang/c++/impl/parsing/ValidatingCodec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ProductionPtr ValidatingGrammarGenerator::doGenerate(const NodePtr &n,
}

struct DummyHandler {
static size_t handle(const Symbol &s) {
static size_t handle(const Symbol &) {
return 0;
}
};
Expand Down
8 changes: 4 additions & 4 deletions lang/c++/test/AvrogencppTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ void testNamespace() {
twPoint.set_AvroPoint(point);
}

void setRecord(uau::r1 &r) {
void setRecord(uau::r1 &) {
}

void check(const uau::r1 &r1, const uau::r1 &r2) {
void check(const uau::r1 &, const uau::r1 &) {
}

void setRecord(umu::r1 &r) {
void setRecord(umu::r1 &) {
}

void check(const umu::r1 &r1, const umu::r1 &r2) {
void check(const umu::r1 &, const umu::r1 &) {
}

template<typename T>
Expand Down
Loading

0 comments on commit 1d1537f

Please sign in to comment.