From f50d87f736d36b748eb17f845323580b906d4a5f Mon Sep 17 00:00:00 2001 From: Dominik Gleich Date: Thu, 9 Nov 2017 13:46:37 +0100 Subject: [PATCH] Take care of warnings/errors created by cppcheck. Summary: Warnings I ignored: Creates a new stacktrace object and then dumps it 102.570384 (102.495075) E[1]: [src/utils/exceptions.hpp:116]: (performance) Variable 'stacktrace_' is assigned in constructor body. Consider performing initialization in initialization list. 102.570390 (102.495081) E[1]: [src/utils/exceptions.hpp:127]: (performance) Variable 'stacktrace_' is assigned in constructor body. Consider performing initialization in initialization list. Used all over the codebase without explicit cast 102.570412 (102.495103) E[1]: [src/utils/stacktrace.hpp:14]: (style) Class 'Line' has a constructor with 1 argument that is not explicit. Not really used anywhere before initialized: 102.570526 (102.495217) E[1]: [src/data_structures/concurrent/skiplist.hpp:467]: (warning) Member variable 'Accessor::preds' is not initialized in the constructor. 102.570530 (102.495221) E[1]: [src/data_structures/concurrent/skiplist.hpp:467]: (warning) Member variable 'Accessor::succs' is not initialized in the constructor. Implicit conversions between types are used all over the codebase: 102.570548 (102.495239) E[1]: [src/storage/property_value.hpp:41]: (style) Class 'PropertyValue' has a constructor with 1 argument that is not explicit. 102.570552 (102.495243) E[1]: [src/storage/property_value.hpp:42]: (style) Class 'PropertyValue' has a constructor with 1 argument that is not explicit. 102.570557 (102.495248) E[1]: [src/storage/property_value.hpp:43]: (style) Class 'PropertyValue' has a constructor with 1 argument that is not explicit. 102.570561 (102.495252) E[1]: [src/storage/property_value.hpp:44]: (style) Class 'PropertyValue' has a constructor with 1 argument that is not explicit. 102.570566 (102.495257) E[1]: [src/storage/property_value.hpp:47]: (style) Class 'PropertyValue' has a constructor with 1 argument that is not explicit. 102.570570 (102.495261) E[1]: [src/storage/property_value.hpp:50]: (style) Class 'PropertyValue' has a constructor with 1 argument that is not explicit. 102.570578 (102.495269) E[1]: [src/storage/property_value.hpp:53]: (style) Class 'PropertyValue' has a constructor with 1 argument that is not explicit. 102.570582 (102.495273) E[1]: [src/storage/property_value.hpp:57]: (style) Class 'PropertyValue' has a constructor with 1 argument that is not explicit. 102.570591 (102.495282) E[1]: [src/query/typed_value.hpp:80]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570596 (102.495287) E[1]: [src/query/typed_value.hpp:81]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570601 (102.495292) E[1]: [src/query/typed_value.hpp:82]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570605 (102.495296) E[1]: [src/query/typed_value.hpp:83]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570609 (102.495300) E[1]: [src/query/typed_value.hpp:89]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570614 (102.495305) E[1]: [src/query/typed_value.hpp:92]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570618 (102.495309) E[1]: [src/query/typed_value.hpp:95]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570623 (102.495314) E[1]: [src/query/typed_value.hpp:98]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570627 (102.495318) E[1]: [src/query/typed_value.hpp:102]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570632 (102.495323) E[1]: [src/query/typed_value.hpp:105]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570636 (102.495327) E[1]: [src/query/typed_value.hpp:108]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570641 (102.495332) E[1]: [src/query/typed_value.hpp:109]: (style) Class 'TypedValue' has a constructor with 1 argument that is not explicit. 102.570645 (102.495336) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:88]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570650 (102.495341) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:89]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570654 (102.495345) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:90]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570659 (102.495350) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:91]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570663 (102.495354) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:94]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570668 (102.495359) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:97]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570672 (102.495363) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:100]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570677 (102.495368) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:104]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570681 (102.495372) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:107]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570690 (102.495381) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:110]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. 102.570694 (102.495385) E[1]: [src/communication/bolt/v1/decoder/decoded_value.hpp:113]: (style) Class 'DecodedValue' has a constructor with 1 argument that is not explicit. CypherParser: 102.570767 (102.495458) E[1]: [src/query/frontend/opencypher/generated/CypherParser.h:69]: (style) Class 'CypherParser' has a constructor with 1 argument that is not explicit. 102.570772 (102.495463) E[1]: [src/query/frontend/opencypher/generated/CypherLexer.h:40]: (style) Class 'CypherLexer' has a constructor with 1 argument that is not explicit. 102.570776 (102.495467) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:86]: (style) The scope of the variable '_la' can be reduced. 102.570781 (102.495472) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:311]: (style) The scope of the variable '_la' can be reduced. 102.570785 (102.495476) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:402]: (style) The scope of the variable '_la' can be reduced. 102.570789 (102.495480) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:497]: (style) The scope of the variable '_la' can be reduced. 102.570797 (102.495488) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:778]: (style) The scope of the variable '_la' can be reduced. 102.570802 (102.495493) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:895]: (style) The scope of the variable '_la' can be reduced. 102.570806 (102.495497) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:991]: (style) The scope of the variable '_la' can be reduced. 102.570811 (102.495502) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:1190]: (style) The scope of the variable '_la' can be reduced. 102.570815 (102.495506) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:1274]: (style) The scope of the variable '_la' can be reduced. 102.570820 (102.495511) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:1393]: (style) The scope of the variable '_la' can be reduced. 102.570824 (102.495515) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:1570]: (style) The scope of the variable '_la' can be reduced. 102.570829 (102.495520) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:1695]: (style) The scope of the variable '_la' can be reduced. 102.570834 (102.495525) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:1800]: (style) The scope of the variable '_la' can be reduced. 102.570839 (102.495530) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:1903]: (style) The scope of the variable '_la' can be reduced. 102.570843 (102.495534) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:2019]: (style) The scope of the variable '_la' can be reduced. 102.570848 (102.495539) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:2228]: (style) The scope of the variable '_la' can be reduced. 102.570852 (102.495543) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:2542]: (style) The scope of the variable '_la' can be reduced. 102.570857 (102.495548) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:2797]: (style) The scope of the variable '_la' can be reduced. 102.570861 (102.495552) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:2966]: (style) The scope of the variable '_la' can be reduced. 102.570866 (102.495557) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:3067]: (style) The scope of the variable '_la' can be reduced. 102.570870 (102.495561) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:3289]: (style) The scope of the variable '_la' can be reduced. 102.570875 (102.495566) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:3295]: (style) The scope of the variable 'alt' can be reduced. 102.570879 (102.495570) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:3419]: (style) The scope of the variable '_la' can be reduced. 102.570884 (102.495575) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:3596]: (style) The scope of the variable '_la' can be reduced. 102.570888 (102.495579) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:3688]: (style) The scope of the variable '_la' can be reduced. 102.570893 (102.495584) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:3963]: (style) The scope of the variable '_la' can be reduced. 102.570897 (102.495588) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:4452]: (style) The scope of the variable '_la' can be reduced. 102.570902 (102.495593) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:4586]: (style) The scope of the variable '_la' can be reduced. 102.570906 (102.495597) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:4813]: (style) The scope of the variable '_la' can be reduced. 102.570911 (102.495602) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:4943]: (style) The scope of the variable '_la' can be reduced. 102.570918 (102.495609) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:5026]: (style) The scope of the variable '_la' can be reduced. 102.570923 (102.495614) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:5569]: (style) The scope of the variable '_la' can be reduced. 102.570928 (102.495619) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:5664]: (style) The scope of the variable '_la' can be reduced. 102.570932 (102.495623) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:5755]: (style) The scope of the variable '_la' can be reduced. 102.570937 (102.495628) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:5888]: (style) The scope of the variable '_la' can be reduced. 102.570941 (102.495632) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:6045]: (style) The scope of the variable '_la' can be reduced. 102.570946 (102.495637) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:6142]: (style) The scope of the variable '_la' can be reduced. 102.570950 (102.495641) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:6347]: (style) The scope of the variable '_la' can be reduced. 102.570955 (102.495646) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:6523]: (style) The scope of the variable '_la' can be reduced. 102.570959 (102.495650) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:6614]: (style) The scope of the variable '_la' can be reduced. 102.570964 (102.495655) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:6899]: (style) The scope of the variable '_la' can be reduced. 102.570968 (102.495659) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:6992]: (style) The scope of the variable '_la' can be reduced. 102.570973 (102.495664) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:7147]: (style) The scope of the variable '_la' can be reduced. 102.570977 (102.495668) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:7680]: (style) The scope of the variable '_la' can be reduced. 102.570982 (102.495673) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:7759]: (style) The scope of the variable '_la' can be reduced. 102.570986 (102.495677) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:7938]: (style) The scope of the variable '_la' can be reduced. 102.570991 (102.495682) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:8126]: (style) The scope of the variable '_la' can be reduced. 102.570995 (102.495686) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:8220]: (style) The scope of the variable '_la' can be reduced. 102.571000 (102.495691) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:8313]: (style) The scope of the variable '_la' can be reduced. 102.571004 (102.495695) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:8491]: (style) The scope of the variable '_la' can be reduced. 102.571009 (102.495700) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:8703]: (style) The scope of the variable '_la' can be reduced. 102.571013 (102.495704) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:8783]: (style) The scope of the variable '_la' can be reduced. 102.571018 (102.495709) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:8914]: (style) The scope of the variable '_la' can be reduced. 102.571022 (102.495713) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:9119]: (style) The scope of the variable '_la' can be reduced. 102.571027 (102.495718) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:9220]: (style) The scope of the variable '_la' can be reduced. 102.571034 (102.495725) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:9414]: (style) The scope of the variable '_la' can be reduced. 102.571039 (102.495730) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:9660]: (style) The scope of the variable '_la' can be reduced. 102.571043 (102.495734) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:10008]: (style) The scope of the variable '_la' can be reduced. 102.571048 (102.495739) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:10158]: (style) The scope of the variable '_la' can be reduced. 102.571052 (102.495743) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:10250]: (style) The scope of the variable '_la' can be reduced. 102.571057 (102.495748) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:10370]: (style) The scope of the variable '_la' can be reduced. 102.571061 (102.495752) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:10637]: (style) The scope of the variable '_la' can be reduced. 102.571065 (102.495756) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:10749]: (style) The scope of the variable '_la' can be reduced. 102.571070 (102.495761) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:10815]: (style) The scope of the variable '_la' can be reduced. 102.571075 (102.495766) E[1]: [src/query/frontend/opencypher/generated/CypherParser.cpp:10881]: (style) The scope of the variable '_la' can be reduced. We know that we represented it correctly in memory: 102.571079 (102.495770) E[1]: [src/communication/bolt/v1/decoder/decoder.hpp:252]: (portability) Casting between integer* and double* which have an incompatible binary data representation. Cont assigned but not used after: 102.571101 (102.495792) E[1]: [src/query/frontend/ast/ast.hpp:1008]: (style) Variable 'cont' is assigned a value that is never used. Reviewers: teon.banek, buda, mferencevic Reviewed By: teon.banek Subscribers: mferencevic, pullbot Differential Revision: https://phabricator.memgraph.io/D967 --- .../bolt/v1/decoder/decoded_value.hpp | 5 +- src/communication/bolt/v1/decoder/decoder.hpp | 12 ++-- .../bolt/v1/encoder/base_encoder.hpp | 6 +- .../bolt/v1/states/executing.hpp | 6 +- .../reactor/reactor_distributed.hpp | 9 +-- src/communication/reactor/reactor_local.hpp | 17 ++--- src/communication/worker.hpp | 4 +- src/data_structures/concurrent/common.hpp | 2 +- src/data_structures/concurrent/push_queue.hpp | 2 +- src/data_structures/concurrent/skiplist.hpp | 17 ++--- src/database/indexes/index_common.hpp | 10 +-- src/durability/hashed_file_writer.hpp | 2 +- src/io/network/addrinfo.hpp | 4 +- src/io/network/epoll.hpp | 4 +- src/io/network/socket.cpp | 5 +- src/io/network/socket_event_dispatcher.hpp | 4 +- src/mvcc/version.hpp | 4 +- src/query/context.hpp | 2 +- src/query/exceptions.hpp | 4 +- src/query/frontend/ast/ast.hpp | 65 +++++++++---------- .../frontend/ast/cypher_main_visitor.hpp | 2 +- .../frontend/semantic/symbol_generator.hpp | 9 +-- src/query/frontend/semantic/symbol_table.hpp | 1 + src/query/path.hpp | 2 +- src/query/plan/operator.cpp | 13 ++-- src/query/plan/operator.hpp | 15 +++-- src/query/plan/preprocess.cpp | 2 +- src/threading/thread.hpp | 2 +- src/transactions/commit_log.hpp | 5 +- src/utils/exceptions.hpp | 22 +++---- src/utils/executor.hpp | 2 +- src/utils/hashing/fnv.hpp | 2 +- src/utils/on_scope_exit.hpp | 5 +- src/utils/stacktrace.hpp | 1 + tools/apollo/cppcheck | 21 +++++- 35 files changed, 152 insertions(+), 136 deletions(-) diff --git a/src/communication/bolt/v1/decoder/decoded_value.hpp b/src/communication/bolt/v1/decoder/decoded_value.hpp index eaa8a5acd..745d0d637 100644 --- a/src/communication/bolt/v1/decoder/decoded_value.hpp +++ b/src/communication/bolt/v1/decoder/decoded_value.hpp @@ -146,7 +146,7 @@ class DecodedValue { #undef DECL_GETTER_BY_REFERNCE #define TYPE_CHECKER(type) \ - bool Is##type() const { return type_ == Type::type ; } + bool Is##type() const { return type_ == Type::type; } TYPE_CHECKER(Bool) TYPE_CHECKER(Int) @@ -161,7 +161,6 @@ class DecodedValue { #undef TYPE_CHECKER - // conversion function to TypedValue operator query::TypedValue() const; @@ -204,4 +203,4 @@ std::ostream &operator<<(std::ostream &os, const DecodedUnboundedEdge &edge); std::ostream &operator<<(std::ostream &os, const DecodedPath &path); std::ostream &operator<<(std::ostream &os, const DecodedValue &value); std::ostream &operator<<(std::ostream &os, const DecodedValue::Type type); -} +} // namespace communication::bolt diff --git a/src/communication/bolt/v1/decoder/decoder.hpp b/src/communication/bolt/v1/decoder/decoder.hpp index 3c46344f0..c8f68d81f 100644 --- a/src/communication/bolt/v1/decoder/decoder.hpp +++ b/src/communication/bolt/v1/decoder/decoder.hpp @@ -21,7 +21,7 @@ namespace communication::bolt { template class Decoder { public: - Decoder(Buffer &buffer) : buffer_(buffer) {} + explicit Decoder(Buffer &buffer) : buffer_(buffer) {} /** * Reads a DecodedValue from the available data in the buffer. @@ -189,7 +189,6 @@ class Decoder { bool ReadInt(const Marker &marker, DecodedValue *data) { uint8_t value = underlying_cast(marker); - bool success = true; int64_t ret; VLOG(1) << "[ReadInt] Start"; if (value >= 240 || value <= 127) { @@ -232,11 +231,9 @@ class Decoder { << underlying_cast(marker); return false; } - if (success) { - *data = DecodedValue(ret); - VLOG(1) << "[ReadInt] Success"; - } - return success; + *data = DecodedValue(ret); + VLOG(1) << "[ReadInt] Success"; + return true; } bool ReadDouble(const Marker marker, DecodedValue *data) { @@ -249,6 +246,7 @@ class Decoder { return false; } value = bswap(value); + // cppcheck-suppress invalidPointerCast ret = *reinterpret_cast(&value); *data = DecodedValue(ret); VLOG(1) << "[ReadDouble] Success"; diff --git a/src/communication/bolt/v1/encoder/base_encoder.hpp b/src/communication/bolt/v1/encoder/base_encoder.hpp index 271193509..09049f8ff 100644 --- a/src/communication/bolt/v1/encoder/base_encoder.hpp +++ b/src/communication/bolt/v1/encoder/base_encoder.hpp @@ -16,7 +16,7 @@ namespace communication::bolt { template class BaseEncoder : public PrimitiveEncoder { public: - BaseEncoder(Buffer &buffer) : PrimitiveEncoder(buffer) {} + explicit BaseEncoder(Buffer &buffer) : PrimitiveEncoder(buffer) {} void WriteList(const std::vector &value) { this->WriteTypeSize(value.size(), MarkerList); @@ -60,7 +60,7 @@ class BaseEncoder : public PrimitiveEncoder { void WriteEdge(const EdgeAccessor &edge, bool unbound = false) { this->WriteRAW(underlying_cast(Marker::TinyStruct) + (unbound ? 3 : 5)); this->WriteRAW(underlying_cast(unbound ? Signature::UnboundRelationship - : Signature::Relationship)); + : Signature::Relationship)); WriteUInt(edge.temporary_id()); if (!unbound) { @@ -163,4 +163,4 @@ class BaseEncoder : public PrimitiveEncoder { this->WriteInt(*reinterpret_cast(&value)); } }; -} +} // namespace communication::bolt diff --git a/src/communication/bolt/v1/states/executing.hpp b/src/communication/bolt/v1/states/executing.hpp index b2c9e0f04..8fb0f2d16 100644 --- a/src/communication/bolt/v1/states/executing.hpp +++ b/src/communication/bolt/v1/states/executing.hpp @@ -148,7 +148,7 @@ State HandleRun(TSession &session, State state, Marker marker) { } auto code_message = [&e]() -> std::pair { - if (const auto *p = dynamic_cast(&e)) { + if (dynamic_cast(&e)) { // Clients expect 4 strings separated by dots. First being database name // (for example: Neo, Memgraph...), second being either ClientError, // TransientError or DatabaseError (or ClientNotification for warnings). @@ -170,7 +170,7 @@ State HandleRun(TSession &session, State state, Marker marker) { // discourage retry of this query. return {"Memgraph.ClientError.MemgraphError.MemgraphError", e.what()}; } - if (const auto *p = dynamic_cast(&e)) { + if (dynamic_cast(&e)) { // Exception not derived from QueryException was thrown which means that // database probably aborted transaction because of some timeout, // deadlock, serialization error or something similar. We return @@ -178,7 +178,7 @@ State HandleRun(TSession &session, State state, Marker marker) { return {"Memgraph.TransientError.MemgraphError.MemgraphError", e.what()}; } - if (const auto *p = dynamic_cast(&e)) { + if (dynamic_cast(&e)) { // std::bad_alloc was thrown, God knows in which state is database -> // terminate. LOG(FATAL) << "Memgraph is out of memory"; diff --git a/src/communication/reactor/reactor_distributed.hpp b/src/communication/reactor/reactor_distributed.hpp index 3a0cd9498..4af8cd7b6 100644 --- a/src/communication/reactor/reactor_distributed.hpp +++ b/src/communication/reactor/reactor_distributed.hpp @@ -50,7 +50,7 @@ class Network { NetworkMessage(const std::string &address, uint16_t port, const std::string &reactor, const std::string &channel, - std::unique_ptr message) + std::unique_ptr &&message) : address(address), port(port), reactor(reactor), @@ -129,8 +129,9 @@ class Network { class RemoteChannelWriter : public ChannelWriter { public: - RemoteChannelWriter(Network *network, std::string address, uint16_t port, - std::string reactor, std::string channel) + RemoteChannelWriter(Network *network, const std::string &address, + uint16_t port, const std::string &reactor, + const std::string &channel) : network_(network), address_(address), port_(port), @@ -271,4 +272,4 @@ class DistributedSystem : public ChannelFinder { DistributedSystem &operator=(const DistributedSystem &) = delete; DistributedSystem &operator=(DistributedSystem &&) = delete; }; -} +} // namespace communication::reactor diff --git a/src/communication/reactor/reactor_local.hpp b/src/communication/reactor/reactor_local.hpp index e7ad3040d..fd24e7b05 100644 --- a/src/communication/reactor/reactor_local.hpp +++ b/src/communication/reactor/reactor_local.hpp @@ -194,7 +194,7 @@ class EventStream { */ class OnEventOnceChainer { public: - OnEventOnceChainer(EventStream &event_stream) + explicit OnEventOnceChainer(EventStream &event_stream) : event_stream_(event_stream) {} ~OnEventOnceChainer() { InstallCallbacks(); } @@ -272,7 +272,7 @@ class Channel { friend class Reactor; // to create a Params initialization object friend class EventStream::Subscription; - Channel(Params params) + explicit Channel(const Params ¶ms) : channel_name_(params.channel_name), reactor_name_(params.reactor_name), mutex_(params.mutex), @@ -294,8 +294,9 @@ class Channel { public: friend class Channel; - LocalChannelWriter(std::string reactor_name, std::string channel_name, - std::weak_ptr queue) + LocalChannelWriter(const std::string &reactor_name, + const std::string &channel_name, + const std::weak_ptr &queue) : reactor_name_(reactor_name), channel_name_(channel_name), queue_(queue) {} @@ -330,7 +331,7 @@ class Channel { public: friend class Channel; - LocalEventStream(std::shared_ptr mutex, Channel *queue) + LocalEventStream(const std::shared_ptr &mutex, Channel *queue) : mutex_(mutex), queue_(queue) {} void OnEventHelper(std::type_index type_index, Callback callback) { @@ -443,8 +444,8 @@ class Channel { class Reactor { friend class System; - Reactor(ChannelFinder &system, std::string name, - std::function setup) + Reactor(ChannelFinder &system, const std::string &name, + const std::function &setup) : system_(system), name_(name), setup_(setup), main_(Open("main")) {} public: @@ -580,4 +581,4 @@ class System : public ChannelFinder { }; using Subscription = Channel::LocalEventStream::Subscription; -} +} // namespace communication::reactor diff --git a/src/communication/worker.hpp b/src/communication/worker.hpp index 7e597fc27..44e0bdfb0 100644 --- a/src/communication/worker.hpp +++ b/src/communication/worker.hpp @@ -53,7 +53,7 @@ class Worker { EPOLLIN | EPOLLRDHUP); } - Worker(TSessionData &session_data) : session_data_(session_data) {} + explicit Worker(TSessionData &session_data) : session_data_(session_data) {} void Start(std::atomic &alive) { while (alive) { @@ -193,4 +193,4 @@ class Worker { io::network::SocketEventDispatcher dispatcher_; std::vector> session_listeners_; }; -} +} // namespace communication diff --git a/src/data_structures/concurrent/common.hpp b/src/data_structures/concurrent/common.hpp index 6ff745a75..304dc48b4 100644 --- a/src/data_structures/concurrent/common.hpp +++ b/src/data_structures/concurrent/common.hpp @@ -51,7 +51,7 @@ class AccessorBase { typedef typename SkipList::ConstIterator list_it_con; protected: - AccessorBase(list *skiplist) : accessor(skiplist->access()) {} + explicit AccessorBase(list *skiplist) : accessor(skiplist->access()) {} public: AccessorBase(const AccessorBase &) = delete; diff --git a/src/data_structures/concurrent/push_queue.hpp b/src/data_structures/concurrent/push_queue.hpp index b491103cb..1840b65e5 100644 --- a/src/data_structures/concurrent/push_queue.hpp +++ b/src/data_structures/concurrent/push_queue.hpp @@ -29,7 +29,7 @@ class ConcurrentPushQueue { // refs to an element, or arguments for emplace creation of // an element template - Node(TArgs &&... args) : element_(std::forward(args)...) {} + explicit Node(TArgs &&... args) : element_(std::forward(args)...) {} // element itself and pointer to next Node TElement element_; diff --git a/src/data_structures/concurrent/skiplist.hpp b/src/data_structures/concurrent/skiplist.hpp index 646a90a29..e436480c7 100644 --- a/src/data_structures/concurrent/skiplist.hpp +++ b/src/data_structures/concurrent/skiplist.hpp @@ -193,7 +193,7 @@ class SkipList : private Lockable { void forward(size_t level, Node *next) { tower[level].store(next); } private: - Node(uint8_t height) : height(height) { + explicit Node(uint8_t height) : height(height) { // here we assume, that the memory for N towers (N = height) has // been allocated right after the Node structure so we need to // initialize that memory @@ -247,7 +247,7 @@ class SkipList : private Lockable { template class IteratorBase : public Crtp { protected: - IteratorBase(Node *node) : node(node) {} + explicit IteratorBase(Node *node) : node(node) {} Node *node{nullptr}; @@ -302,7 +302,7 @@ class SkipList : private Lockable { class ConstIterator : public IteratorBase { friend class SkipList; - ConstIterator(Node *node) : IteratorBase(node) {} + explicit ConstIterator(Node *node) : IteratorBase(node) {} public: ConstIterator() = default; @@ -321,7 +321,7 @@ class SkipList : private Lockable { class Iterator : public IteratorBase { friend class SkipList; - Iterator(Node *node) : IteratorBase(node) {} + explicit Iterator(Node *node) : IteratorBase(node) {} public: Iterator() = default; @@ -347,7 +347,7 @@ class SkipList : private Lockable { class ReverseIterator : public Crtp { friend class SkipList; - ReverseIterator(Node *node) : node_(node) {} + explicit ReverseIterator(Node *node) : node_(node) {} public: ReverseIterator(SkipList *skiplist, Node *node, Node *preds[]) @@ -456,7 +456,7 @@ class SkipList : private Lockable { class Accessor { friend class SkipList; - Accessor(TSkipList *skiplist) + explicit Accessor(TSkipList *skiplist) : skiplist(skiplist), status_(skiplist->gc.CreateNewAccessor()) { DCHECK(skiplist != nullptr) << "Skiplist is nullptr."; } @@ -464,6 +464,7 @@ class SkipList : private Lockable { public: Accessor(const Accessor &) = delete; + // cppcheck-suppress uninitMemberVar Accessor(Accessor &&other) : skiplist(other.skiplist), status_(other.status_) { other.skiplist = nullptr; @@ -863,11 +864,11 @@ class SkipList : private Lockable { template static bool lock_nodes(uint8_t height, guard_t guards[], Node *preds[], Node *succs[]) { - Node *prepred = nullptr, *pred = nullptr, *succ = nullptr; + Node *prepred = nullptr; bool valid = true; for (int level = 0; valid && level < height; ++level) { - pred = preds[level], succ = succs[level]; + Node *pred = preds[level], *succ = succs[level]; if (pred != prepred) guards[level] = pred->acquire_unique(), prepred = pred; diff --git a/src/database/indexes/index_common.hpp b/src/database/indexes/index_common.hpp index d82d138b1..1aa22a2b4 100644 --- a/src/database/indexes/index_common.hpp +++ b/src/database/indexes/index_common.hpp @@ -23,7 +23,7 @@ class SkipListSuffix { public: class Iterator { public: - Iterator(TIterator current) : current_(current) {} + explicit Iterator(TIterator current) : current_(current) {} TValue &operator*() { return *current_; } @@ -40,7 +40,7 @@ class SkipListSuffix { TIterator current_; }; - SkipListSuffix( + explicit SkipListSuffix( const TIterator begin, typename SkipList::template Accessor &&accessor) : begin_(begin), accessor_(std::move(accessor)) {} @@ -79,9 +79,9 @@ static auto GetVlists( typename SkipList::template Accessor &&skiplist_accessor, TIterator begin, - const std::function predicate, + const std::function &predicate, const tx::Transaction &t, - const std::function exists, + const std::function &exists, bool current_state = false) { TIndexEntry *prev = nullptr; auto range = iter::takewhile( @@ -141,7 +141,7 @@ template static void Refresh( ConcurrentMap *> &indices, const tx::Snapshot &snapshot, tx::Engine &engine, - const std::function exists) { + const std::function &exists) { // iterate over all the indices for (auto &key_indices_pair : indices.access()) { // iterate over index entries diff --git a/src/durability/hashed_file_writer.hpp b/src/durability/hashed_file_writer.hpp index 948b95a1a..19480d0cc 100644 --- a/src/durability/hashed_file_writer.hpp +++ b/src/durability/hashed_file_writer.hpp @@ -17,7 +17,7 @@ class HashedFileWriter { } /** Constructor which also takes a file path and opens it immediately. */ - HashedFileWriter(const std::string &path) : HashedFileWriter() { + explicit HashedFileWriter(const std::string &path) : HashedFileWriter() { output_stream_.open(path, std::ios::out | std::ios::binary); } diff --git a/src/io/network/addrinfo.hpp b/src/io/network/addrinfo.hpp index cd749bf9d..c9ddad683 100644 --- a/src/io/network/addrinfo.hpp +++ b/src/io/network/addrinfo.hpp @@ -7,7 +7,7 @@ namespace io::network { * see: man 3 getaddrinfo */ class AddrInfo { - AddrInfo(struct addrinfo *info); + explicit AddrInfo(struct addrinfo *info); public: ~AddrInfo(); @@ -19,4 +19,4 @@ class AddrInfo { private: struct addrinfo *info; }; -} +} // namespace io::network diff --git a/src/io/network/epoll.hpp b/src/io/network/epoll.hpp index 66c6ddbf2..5e3814741 100644 --- a/src/io/network/epoll.hpp +++ b/src/io/network/epoll.hpp @@ -21,7 +21,7 @@ class Epoll { public: using Event = struct epoll_event; - Epoll(int flags) : epoll_fd_(epoll_create1(flags)) { + explicit Epoll(int flags) : epoll_fd_(epoll_create1(flags)) { // epoll_create1 returns an error if there is a logical error in our code // (for example invalid flags) or if there is irrecoverable error. In both // cases it is best to terminate. @@ -54,4 +54,4 @@ class Epoll { private: const int epoll_fd_; }; -} +} // namespace io::network diff --git a/src/io/network/socket.cpp b/src/io/network/socket.cpp index a90eaeac8..3f1107235 100644 --- a/src/io/network/socket.cpp +++ b/src/io/network/socket.cpp @@ -168,7 +168,6 @@ std::experimental::optional Socket::Accept() { char addr_decoded[INET6_ADDRSTRLEN]; void *addr_src; unsigned short port; - unsigned char family; int sfd = accept(socket_, (struct sockaddr *)&addr, &addr_size); if (UNLIKELY(sfd == -1)) return std::experimental::nullopt; @@ -176,11 +175,9 @@ std::experimental::optional Socket::Accept() { if (addr.ss_family == AF_INET) { addr_src = (void *)&(((sockaddr_in *)&addr)->sin_addr); port = ntohs(((sockaddr_in *)&addr)->sin_port); - family = 4; } else { addr_src = (void *)&(((sockaddr_in6 *)&addr)->sin6_addr); port = ntohs(((sockaddr_in6 *)&addr)->sin6_port); - family = 6; } inet_ntop(addr.ss_family, addr_src, addr_decoded, INET6_ADDRSTRLEN); @@ -229,4 +226,4 @@ bool Socket::Write(const std::string &s, int Socket::Read(void *buffer, size_t len) { return read(socket_, buffer, len); } -} +} // namespace io::network diff --git a/src/io/network/socket_event_dispatcher.hpp b/src/io/network/socket_event_dispatcher.hpp index 09627375a..9ae019222 100644 --- a/src/io/network/socket_event_dispatcher.hpp +++ b/src/io/network/socket_event_dispatcher.hpp @@ -15,7 +15,7 @@ namespace io::network { template class SocketEventDispatcher { public: - SocketEventDispatcher(uint32_t flags = 0) : epoll_(flags) {} + explicit SocketEventDispatcher(uint32_t flags = 0) : epoll_(flags) {} void AddListener(int fd, Listener &listener, uint32_t events) { // Add the listener associated to fd file descriptor to epoll. @@ -78,7 +78,7 @@ class SocketEventDispatcher { */ class BaseListener { public: - BaseListener(Socket &socket) : socket_(socket) {} + explicit BaseListener(Socket &socket) : socket_(socket) {} void OnClose() { socket_.Close(); } diff --git a/src/mvcc/version.hpp b/src/mvcc/version.hpp index 3037b766d..334704e8f 100644 --- a/src/mvcc/version.hpp +++ b/src/mvcc/version.hpp @@ -8,7 +8,7 @@ template class Version { public: Version() = default; - Version(T *older) : older_(older) {} + explicit Version(T *older) : older_(older) {} ~Version() { delete older_.load(std::memory_order_seq_cst); } @@ -29,4 +29,4 @@ class Version { private: std::atomic older_{nullptr}; }; -} +} // namespace mvcc diff --git a/src/query/context.hpp b/src/query/context.hpp index df922fe1e..cf0e8e2cb 100644 --- a/src/query/context.hpp +++ b/src/query/context.hpp @@ -16,7 +16,7 @@ class Context { Context(Context &&) = default; Context &operator=(Context &&) = default; - Context(GraphDbAccessor &db_accessor) : db_accessor_(db_accessor) {} + explicit Context(GraphDbAccessor &db_accessor) : db_accessor_(db_accessor) {} GraphDbAccessor &db_accessor_; SymbolTable symbol_table_; Parameters parameters_; diff --git a/src/query/exceptions.hpp b/src/query/exceptions.hpp index 0fdc95d50..82028df9e 100644 --- a/src/query/exceptions.hpp +++ b/src/query/exceptions.hpp @@ -45,13 +45,13 @@ class SemanticException : public QueryException { class UnboundVariableError : public SemanticException { public: - UnboundVariableError(const std::string &name) + explicit UnboundVariableError(const std::string &name) : SemanticException("Unbound variable: " + name) {} }; class RedeclareVariableError : public SemanticException { public: - RedeclareVariableError(const std::string &name) + explicit RedeclareVariableError(const std::string &name) : SemanticException("Redeclaring variable: " + name) {} }; diff --git a/src/query/frontend/ast/ast.hpp b/src/query/frontend/ast/ast.hpp index b79ddfb62..7f6a52fba 100644 --- a/src/query/frontend/ast/ast.hpp +++ b/src/query/frontend/ast/ast.hpp @@ -87,7 +87,7 @@ class Tree : public ::utils::Visitable, virtual Tree *Clone(AstTreeStorage &storage) const = 0; protected: - Tree(int uid) : uid_(uid) {} + explicit Tree(int uid) : uid_(uid) {} private: const int uid_; @@ -102,7 +102,7 @@ class Expression : public Tree { Expression *Clone(AstTreeStorage &storage) const override = 0; protected: - Expression(int uid) : Tree(uid) {} + explicit Expression(int uid) : Tree(uid) {} }; class Where : public Tree { @@ -124,7 +124,7 @@ class Where : public Tree { Expression *expression_ = nullptr; protected: - Where(int uid) : Tree(uid) {} + explicit Where(int uid) : Tree(uid) {} Where(int uid, Expression *expression) : Tree(uid), expression_(expression) {} }; @@ -138,7 +138,7 @@ class BinaryOperator : public Expression { BinaryOperator *Clone(AstTreeStorage &storage) const override = 0; protected: - BinaryOperator(int uid) : Expression(uid) {} + explicit BinaryOperator(int uid) : Expression(uid) {} BinaryOperator(int uid, Expression *expression1, Expression *expression2) : Expression(uid), expression1_(expression1), expression2_(expression2) {} }; @@ -152,7 +152,7 @@ class UnaryOperator : public Expression { UnaryOperator *Clone(AstTreeStorage &storage) const override = 0; protected: - UnaryOperator(int uid) : Expression(uid) {} + explicit UnaryOperator(int uid) : Expression(uid) {} UnaryOperator(int uid, Expression *expression) : Expression(uid), expression_(expression) {} }; @@ -580,7 +580,7 @@ class BaseLiteral : public Expression { BaseLiteral *Clone(AstTreeStorage &storage) const override = 0; protected: - BaseLiteral(int uid) : Expression(uid) {} + explicit BaseLiteral(int uid) : Expression(uid) {} }; class PrimitiveLiteral : public BaseLiteral { @@ -601,7 +601,7 @@ class PrimitiveLiteral : public BaseLiteral { int token_position_ = -1; protected: - PrimitiveLiteral(int uid) : BaseLiteral(uid) {} + explicit PrimitiveLiteral(int uid) : BaseLiteral(uid) {} template PrimitiveLiteral(int uid, T value) : BaseLiteral(uid), value_(value) {} template @@ -633,7 +633,7 @@ class ListLiteral : public BaseLiteral { std::vector elements_; protected: - ListLiteral(int uid) : BaseLiteral(uid) {} + explicit ListLiteral(int uid) : BaseLiteral(uid) {} ListLiteral(int uid, const std::vector &elements) : BaseLiteral(uid), elements_(elements) {} }; @@ -664,7 +664,7 @@ class MapLiteral : public BaseLiteral { elements_; protected: - MapLiteral(int uid) : BaseLiteral(uid) {} + explicit MapLiteral(int uid) : BaseLiteral(uid) {} MapLiteral( int uid, const std::unordered_map, @@ -722,7 +722,7 @@ class PropertyLookup : public Expression { property_name_(property_name), property_(property) {} PropertyLookup(int uid, Expression *expression, - std::pair property) + const std::pair &property) : Expression(uid), expression_(expression), property_name_(property.first), @@ -750,7 +750,7 @@ class LabelsTest : public Expression { protected: LabelsTest(int uid, Expression *expression, - std::vector labels) + const std::vector &labels) : Expression(uid), expression_(expression), labels_(labels) {} }; @@ -783,9 +783,8 @@ class Function : public Expression { protected: Function(int uid, - std::function &, - GraphDbAccessor &)> - function, + const std::function &, + GraphDbAccessor &)> &function, const std::vector &arguments) : Expression(uid), function_(function), arguments_(arguments) {} }; @@ -827,7 +826,7 @@ class Aggregation : public BinaryOperator { // COUNT without expression denotes COUNT(*) in cypher. DCHECK(expression1 || op == Aggregation::Op::COUNT) << "All aggregations, except COUNT require expression"; - DCHECK(expression2 == nullptr ^ op == Aggregation::Op::COLLECT_MAP) + DCHECK((expression2 == nullptr) ^ (op == Aggregation::Op::COLLECT_MAP)) << "The second expression is obligatory in COLLECT_MAP and " "invalid otherwise"; } @@ -886,7 +885,7 @@ class ParameterLookup : public Expression { int token_position_ = -1; protected: - ParameterLookup(int uid) : Expression(uid) {} + explicit ParameterLookup(int uid) : Expression(uid) {} ParameterLookup(int uid, int token_position) : Expression(uid), token_position_(token_position) {} }; @@ -916,7 +915,7 @@ class NamedExpression : public Tree { int token_position_ = -1; protected: - NamedExpression(int uid) : Tree(uid) {} + explicit NamedExpression(int uid) : Tree(uid) {} NamedExpression(int uid, const std::string &name) : Tree(uid), name_(name) {} NamedExpression(int uid, const std::string &name, Expression *expression) : Tree(uid), name_(name), expression_(expression) {} @@ -939,7 +938,7 @@ class PatternAtom : public Tree { PatternAtom *Clone(AstTreeStorage &storage) const override = 0; protected: - PatternAtom(int uid) : Tree(uid) {} + explicit PatternAtom(int uid) : Tree(uid) {} PatternAtom(int uid, Identifier *identifier) : Tree(uid), identifier_(identifier) {} }; @@ -1005,7 +1004,7 @@ class EdgeAtom : public PatternAtom { cont = lower_bound_->Accept(visitor); } if (cont && upper_bound_) { - cont = upper_bound_->Accept(visitor); + upper_bound_->Accept(visitor); } } return visitor.PostVisit(*this); @@ -1095,7 +1094,7 @@ class Pattern : public Tree { std::vector atoms_; protected: - Pattern(int uid) : Tree(uid) {} + explicit Pattern(int uid) : Tree(uid) {} }; // Clauses @@ -1104,7 +1103,7 @@ class Clause : public Tree { friend class AstTreeStorage; public: - Clause(int uid) : Tree(uid) {} + explicit Clause(int uid) : Tree(uid) {} Clause *Clone(AstTreeStorage &storage) const override = 0; }; @@ -1135,14 +1134,14 @@ class Query : public Tree { std::vector clauses_; protected: - Query(int uid) : Tree(uid) {} + explicit Query(int uid) : Tree(uid) {} }; class Create : public Clause { friend class AstTreeStorage; public: - Create(int uid) : Clause(uid) {} + explicit Create(int uid) : Clause(uid) {} DEFVISITABLE(TreeVisitor); bool Accept(HierarchicalTreeVisitor &visitor) override { if (visitor.PreVisit(*this)) { @@ -1199,7 +1198,7 @@ class Match : public Clause { bool optional_ = false; protected: - Match(int uid) : Clause(uid) {} + explicit Match(int uid) : Clause(uid) {} Match(int uid, bool optional) : Clause(uid), optional_(optional) {} }; @@ -1266,7 +1265,7 @@ class Return : public Clause { ReturnBody body_; protected: - Return(int uid) : Clause(uid) {} + explicit Return(int uid) : Clause(uid) {} }; class With : public Clause { @@ -1309,7 +1308,7 @@ class With : public Clause { Where *where_ = nullptr; protected: - With(int uid) : Clause(uid) {} + explicit With(int uid) : Clause(uid) {} }; class Delete : public Clause { @@ -1339,7 +1338,7 @@ class Delete : public Clause { bool detach_ = false; protected: - Delete(int uid) : Clause(uid) {} + explicit Delete(int uid) : Clause(uid) {} }; class SetProperty : public Clause { @@ -1363,7 +1362,7 @@ class SetProperty : public Clause { Expression *expression_ = nullptr; protected: - SetProperty(int uid) : Clause(uid) {} + explicit SetProperty(int uid) : Clause(uid) {} SetProperty(int uid, PropertyLookup *property_lookup, Expression *expression) : Clause(uid), property_lookup_(property_lookup), @@ -1392,7 +1391,7 @@ class SetProperties : public Clause { bool update_ = false; protected: - SetProperties(int uid) : Clause(uid) {} + explicit SetProperties(int uid) : Clause(uid) {} SetProperties(int uid, Identifier *identifier, Expression *expression, bool update = false) : Clause(uid), @@ -1421,7 +1420,7 @@ class SetLabels : public Clause { std::vector labels_; protected: - SetLabels(int uid) : Clause(uid) {} + explicit SetLabels(int uid) : Clause(uid) {} SetLabels(int uid, Identifier *identifier, const std::vector &labels) : Clause(uid), identifier_(identifier), labels_(labels) {} @@ -1446,7 +1445,7 @@ class RemoveProperty : public Clause { PropertyLookup *property_lookup_ = nullptr; protected: - RemoveProperty(int uid) : Clause(uid) {} + explicit RemoveProperty(int uid) : Clause(uid) {} RemoveProperty(int uid, PropertyLookup *property_lookup) : Clause(uid), property_lookup_(property_lookup) {} }; @@ -1471,7 +1470,7 @@ class RemoveLabels : public Clause { std::vector labels_; protected: - RemoveLabels(int uid) : Clause(uid) {} + explicit RemoveLabels(int uid) : Clause(uid) {} RemoveLabels(int uid, Identifier *identifier, const std::vector &labels) : Clause(uid), identifier_(identifier), labels_(labels) {} @@ -1522,7 +1521,7 @@ class Merge : public Clause { std::vector on_create_; protected: - Merge(int uid) : Clause(uid) {} + explicit Merge(int uid) : Clause(uid) {} }; class Unwind : public Clause { diff --git a/src/query/frontend/ast/cypher_main_visitor.hpp b/src/query/frontend/ast/cypher_main_visitor.hpp index 7f36b8e57..ee7a9f824 100644 --- a/src/query/frontend/ast/cypher_main_visitor.hpp +++ b/src/query/frontend/ast/cypher_main_visitor.hpp @@ -21,7 +21,7 @@ using query::Context; class CypherMainVisitor : public antlropencypher::CypherBaseVisitor { public: - CypherMainVisitor(Context &ctx) : ctx_(ctx) {} + explicit CypherMainVisitor(Context &ctx) : ctx_(ctx) {} private: Expression *CreateBinaryOperatorByToken(size_t token, Expression *e1, diff --git a/src/query/frontend/semantic/symbol_generator.hpp b/src/query/frontend/semantic/symbol_generator.hpp index 2a8bba486..7eba55d18 100644 --- a/src/query/frontend/semantic/symbol_generator.hpp +++ b/src/query/frontend/semantic/symbol_generator.hpp @@ -18,12 +18,13 @@ namespace query { /// variable types. class SymbolGenerator : public HierarchicalTreeVisitor { public: - SymbolGenerator(SymbolTable &symbol_table) : symbol_table_(symbol_table) {} + explicit SymbolGenerator(SymbolTable &symbol_table) + : symbol_table_(symbol_table) {} - using HierarchicalTreeVisitor::PreVisit; - using typename HierarchicalTreeVisitor::ReturnType; - using HierarchicalTreeVisitor::Visit; using HierarchicalTreeVisitor::PostVisit; + using HierarchicalTreeVisitor::PreVisit; + using HierarchicalTreeVisitor::Visit; + using typename HierarchicalTreeVisitor::ReturnType; // Clauses bool PreVisit(Create &) override; diff --git a/src/query/frontend/semantic/symbol_table.hpp b/src/query/frontend/semantic/symbol_table.hpp index 610fefdae..00e221692 100644 --- a/src/query/frontend/semantic/symbol_table.hpp +++ b/src/query/frontend/semantic/symbol_table.hpp @@ -50,6 +50,7 @@ class Symbol { class SymbolTable { public: + SymbolTable() {} Symbol CreateSymbol(const std::string &name, bool user_declared, Symbol::Type type = Symbol::Type::Any, int token_position = -1) { diff --git a/src/query/path.hpp b/src/query/path.hpp index c68872c22..e8015daf6 100644 --- a/src/query/path.hpp +++ b/src/query/path.hpp @@ -18,7 +18,7 @@ namespace query { class Path { public: /** Creates the path starting with the given vertex. */ - Path(const VertexAccessor &vertex) { Expand(vertex); } + explicit Path(const VertexAccessor &vertex) { Expand(vertex); } /** Creates the path starting with the given vertex and containing all other * elements. */ diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 481c747a4..281fabbe3 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -206,8 +206,9 @@ void CreateExpand::CreateExpandCursor::CreateEdge( template class ScanAllCursor : public Cursor { public: - ScanAllCursor(Symbol output_symbol, std::unique_ptr input_cursor, - TVerticesFun get_vertices, GraphDbAccessor &db) + explicit ScanAllCursor(Symbol output_symbol, + std::unique_ptr &&input_cursor, + TVerticesFun &&get_vertices, GraphDbAccessor &db) : output_symbol_(output_symbol), input_cursor_(std::move(input_cursor)), get_vertices_(std::move(get_vertices)), @@ -1132,7 +1133,7 @@ bool Filter::FilterCursor::Pull(Frame &frame, Context &context) { void Filter::FilterCursor::Reset() { input_cursor_->Reset(); } Produce::Produce(const std::shared_ptr &input, - const std::vector named_expressions) + const std::vector &named_expressions) : input_(input ? input : std::make_shared()), named_expressions_(named_expressions) {} @@ -2160,9 +2161,9 @@ bool OrderBy::TypedValueVectorCompare::operator()( return (c1_it == c1.end()) && (c2_it != c2.end()); } -Merge::Merge(const std::shared_ptr input, - const std::shared_ptr merge_match, - const std::shared_ptr merge_create) +Merge::Merge(const std::shared_ptr &input, + const std::shared_ptr &merge_match, + const std::shared_ptr &merge_create) : input_(input ? input : std::make_shared()), merge_match_(merge_match), merge_create_(merge_create) {} diff --git a/src/query/plan/operator.hpp b/src/query/plan/operator.hpp index 78ca70d36..a8130845f 100644 --- a/src/query/plan/operator.hpp +++ b/src/query/plan/operator.hpp @@ -110,10 +110,10 @@ class HierarchicalLogicalOperatorVisitor : public LogicalOperatorCompositeVisitor, public LogicalOperatorLeafVisitor { public: - using LogicalOperatorCompositeVisitor::PreVisit; using LogicalOperatorCompositeVisitor::PostVisit; - using typename LogicalOperatorLeafVisitor::ReturnType; + using LogicalOperatorCompositeVisitor::PreVisit; using LogicalOperatorLeafVisitor::Visit; + using typename LogicalOperatorLeafVisitor::ReturnType; }; /** @brief Base class for logical operators. @@ -160,6 +160,7 @@ class Once : public LogicalOperator { private: class OnceCursor : public Cursor { public: + OnceCursor() {} bool Pull(Frame &, Context &) override; void Reset() override; @@ -727,7 +728,7 @@ class Filter : public LogicalOperator { class Produce : public LogicalOperator { public: Produce(const std::shared_ptr &input, - const std::vector named_expressions); + const std::vector &named_expressions); bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override; std::unique_ptr MakeCursor(GraphDbAccessor &db) const override; std::vector OutputSymbols(const SymbolTable &) const override; @@ -1312,7 +1313,7 @@ class OrderBy : public LogicalOperator { class TypedValueVectorCompare { public: TypedValueVectorCompare() {} - TypedValueVectorCompare(const std::vector &ordering) + explicit TypedValueVectorCompare(const std::vector &ordering) : ordering_(ordering) {} bool operator()(const std::vector &c1, const std::vector &c2) const; @@ -1370,9 +1371,9 @@ class OrderBy : public LogicalOperator { */ class Merge : public LogicalOperator { public: - Merge(const std::shared_ptr input, - const std::shared_ptr merge_match, - const std::shared_ptr merge_create); + Merge(const std::shared_ptr &input, + const std::shared_ptr &merge_match, + const std::shared_ptr &merge_create); bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override; std::unique_ptr MakeCursor(GraphDbAccessor &db) const override; diff --git a/src/query/plan/preprocess.cpp b/src/query/plan/preprocess.cpp index 729d7b75d..6bc7393de 100644 --- a/src/query/plan/preprocess.cpp +++ b/src/query/plan/preprocess.cpp @@ -406,7 +406,7 @@ FilterInfo Filters::AnalyzeFilter(Expression *expr, if (auto *labels_test = dynamic_cast(expr)) { // Since LabelsTest may contain any expression, we can only use the // simplest test on an identifier. - if (auto *ident = dynamic_cast(labels_test->expression_)) { + if (dynamic_cast(labels_test->expression_)) { filter.type = FilterInfo::Type::Label; filter.labels = labels_test->labels_; } diff --git a/src/threading/thread.hpp b/src/threading/thread.hpp index bb773f1fb..d28bb94aa 100644 --- a/src/threading/thread.hpp +++ b/src/threading/thread.hpp @@ -15,7 +15,7 @@ class Thread { static constexpr unsigned MAIN_THREAD = 0; template - Thread(F f) { + explicit Thread(F f) { thread_id = thread_counter.fetch_add(1, std::memory_order_acq_rel); thread = std::thread([this, f]() { start_thread(f); }); } diff --git a/src/transactions/commit_log.hpp b/src/transactions/commit_log.hpp index 92b6d4480..da96b8c40 100644 --- a/src/transactions/commit_log.hpp +++ b/src/transactions/commit_log.hpp @@ -38,7 +38,8 @@ class CommitLog { COMMITTED = 1, // 01 ABORTED = 2, // 10 }; - Info(uint8_t flags) : flags_(flags) {} + + explicit Info(uint8_t flags) : flags_(flags) {} bool is_active() const { return flags_ == ACTIVE; } @@ -57,4 +58,4 @@ class CommitLog { private: DynamicBitset log; }; -} +} // namespace tx diff --git a/src/utils/exceptions.hpp b/src/utils/exceptions.hpp index 7821d0def..7cc2c55eb 100644 --- a/src/utils/exceptions.hpp +++ b/src/utils/exceptions.hpp @@ -41,8 +41,8 @@ class BasicException : public std::exception { * * @param message The error message. */ - explicit BasicException(const std::string &message) noexcept : msg_(message) { - } + explicit BasicException(const std::string &message) noexcept + : msg_(message) {} /** * @brief Constructor with format string (C++ STL strings). @@ -64,8 +64,8 @@ class BasicException : public std::exception { */ template explicit BasicException(const char *format, Args &&... args) noexcept - : BasicException(fmt::format(std::string(format), - std::forward(args)...)) {} + : BasicException( + fmt::format(std::string(format), std::forward(args)...)) {} /** * @brief Virtual destructor to allow for subclassing. @@ -111,10 +111,7 @@ class StacktraceException : public std::exception { * with the caller. */ explicit StacktraceException(const char *message) noexcept - : message_(message) { - Stacktrace stacktrace; - stacktrace_ = stacktrace.dump(); - } + : message_(message), stacktrace_(Stacktrace().dump()) {} /** * @brief Constructor (C++ STL strings). @@ -122,10 +119,7 @@ class StacktraceException : public std::exception { * @param message The error message. */ explicit StacktraceException(const std::string &message) noexcept - : message_(message) { - Stacktrace stacktrace; - stacktrace_ = stacktrace.dump(); - } + : message_(message), stacktrace_(Stacktrace().dump()) {} /** * @brief Constructor with format string (C++ STL strings). @@ -148,8 +142,8 @@ class StacktraceException : public std::exception { */ template explicit StacktraceException(const char *format, Args &&... args) noexcept - : StacktraceException(fmt::format(std::string(format), - std::forward(args)...)) {} + : StacktraceException( + fmt::format(std::string(format), std::forward(args)...)) {} /** * @brief Virtual destructor to allow for subclassing. diff --git a/src/utils/executor.hpp b/src/utils/executor.hpp index c6018cae9..1f4318350 100644 --- a/src/utils/executor.hpp +++ b/src/utils/executor.hpp @@ -13,7 +13,7 @@ class Executor { public: template - Executor(const std::chrono::duration pause) { + explicit Executor(const std::chrono::duration pause) { if (pause != pause.zero()) scheduler_.Run(pause, std::bind(&Executor::Execute, this)); } diff --git a/src/utils/hashing/fnv.hpp b/src/utils/hashing/fnv.hpp index 8338dd906..39bb60117 100644 --- a/src/utils/hashing/fnv.hpp +++ b/src/utils/hashing/fnv.hpp @@ -21,7 +21,7 @@ __attribute__((unused)) uint64_t fnv(const std::string &s) { using HashType = uint64_t; -#elif +#else __attribute__((unused)) uint32_t fnv(const std::string &s) { return fnv1a32(s); diff --git a/src/utils/on_scope_exit.hpp b/src/utils/on_scope_exit.hpp index 9b63e7f86..10584bf39 100644 --- a/src/utils/on_scope_exit.hpp +++ b/src/utils/on_scope_exit.hpp @@ -25,10 +25,11 @@ namespace utils { */ class OnScopeExit { public: - OnScopeExit(const std::function function) : function_(function) {} + explicit OnScopeExit(const std::function &function) + : function_(function) {} ~OnScopeExit() { function_(); } private: std::function function_; }; -} +} // namespace utils diff --git a/src/utils/stacktrace.hpp b/src/utils/stacktrace.hpp index 20556e402..5062913ba 100644 --- a/src/utils/stacktrace.hpp +++ b/src/utils/stacktrace.hpp @@ -11,6 +11,7 @@ class Stacktrace { public: class Line { public: + // cppcheck-suppress noExplicitConstructor Line(const std::string &original) : original(original) {} Line(const std::string &original, const std::string &function, diff --git a/tools/apollo/cppcheck b/tools/apollo/cppcheck index bc471d80b..e72635864 100755 --- a/tools/apollo/cppcheck +++ b/tools/apollo/cppcheck @@ -19,7 +19,26 @@ else files=src/ flags="-j$THREADS -Isrc" fi -cppcheck --enable=all --force --suppress=missingInclude --suppress=unusedFunction --suppress=unusedStructMember $flags $files 2>"$tmpfile" + +cat > .cppcheck_suppressions <"$tmpfile" +rm .cppcheck_suppressions cat "$tmpfile" | grep -v "(information) Unmatched suppression" > "$errfile" rm $tmpfile