diff --git a/src/object-store/CMake/CompilerFlags.cmake b/src/object-store/CMake/CompilerFlags.cmake index c214b625..aa66987b 100644 --- a/src/object-store/CMake/CompilerFlags.cmake +++ b/src/object-store/CMake/CompilerFlags.cmake @@ -1,9 +1,32 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED on) set(CMAKE_CXX_EXTENSIONS off) -add_compile_options(-Wall -DREALM_HAVE_CONFIG) add_compile_options("$<$:-DREALM_DEBUG>") add_compile_options("$<$:-DREALM_DEBUG>") +add_compile_options( + -DREALM_HAVE_CONFIG + -Wall + -Wextra + -Wno-missing-field-initializers + -Wempty-body + -Wparentheses + -Wunknown-pragmas + -Wunreachable-code +) + +if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") + add_compile_options( + -Wassign-enum + -Wbool-conversion + -Wconditional-uninitialized + -Wconstant-conversion + -Wenum-conversion + -Wint-conversion + -Wmissing-prototypes + -Wnewline-eof + -Wshorten-64-to-32 + ) +endif() if(${CMAKE_GENERATOR} STREQUAL "Ninja") if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") diff --git a/src/object-store/src/object_accessor.hpp b/src/object-store/src/object_accessor.hpp index 4df51508..84d07387 100644 --- a/src/object-store/src/object_accessor.hpp +++ b/src/object-store/src/object_accessor.hpp @@ -123,7 +123,7 @@ namespace realm { // // Deprecated // - static Mixed to_mixed(ContextType ctx, ValueType &val) { throw std::runtime_error("'Any' type is unsupported"); } + static Mixed to_mixed(ContextType, ValueType&) { throw std::runtime_error("'Any' type is unsupported"); } }; class InvalidatedObjectException : public std::runtime_error diff --git a/src/object-store/src/parser/parser.cpp b/src/object-store/src/parser/parser.cpp index dab01c63..6b7c3396 100644 --- a/src/object-store/src/parser/parser.cpp +++ b/src/object-store/src/parser/parser.cpp @@ -201,14 +201,14 @@ template< typename Rule > struct action : nothing< Rule > {}; #ifdef REALM_PARSER_PRINT_TOKENS - #define DEBUG_PRINT_TOKEN(string) std::cout << string << std::endl + #define DEBUG_PRINT_TOKEN(string) do { std::cout << string << std::endl; while (0) #else - #define DEBUG_PRINT_TOKEN(string) + #define DEBUG_PRINT_TOKEN(string) do { static_cast(string); } while (0) #endif template<> struct action< and_op > { - static void apply( const input & in, ParserState & state ) + static void apply(const input&, ParserState& state) { DEBUG_PRINT_TOKEN(""); state.next_type = Predicate::Type::And; @@ -217,7 +217,7 @@ template<> struct action< and_op > template<> struct action< or_op > { - static void apply( const input & in, ParserState & state ) + static void apply(const input&, ParserState & state) { DEBUG_PRINT_TOKEN(""); state.next_type = Predicate::Type::Or; @@ -227,7 +227,7 @@ template<> struct action< or_op > #define EXPRESSION_ACTION(rule, type) \ template<> struct action< rule > { \ - static void apply( const input & in, ParserState & state ) { \ + static void apply(const input& in, ParserState& state) { \ DEBUG_PRINT_TOKEN(in.string()); \ state.add_expression(Expression(type, in.string())); }}; @@ -239,10 +239,10 @@ EXPRESSION_ACTION(true_value, Expression::Type::True) EXPRESSION_ACTION(false_value, Expression::Type::False) EXPRESSION_ACTION(null_value, Expression::Type::Null) EXPRESSION_ACTION(argument_index, Expression::Type::Argument) - + template<> struct action< true_pred > { - static void apply( const input & in, ParserState & state ) + static void apply(const input& in, ParserState & state) { DEBUG_PRINT_TOKEN(in.string()); state.current_group()->cpnd.sub_predicates.emplace_back(Predicate::Type::True); @@ -251,7 +251,7 @@ template<> struct action< true_pred > template<> struct action< false_pred > { - static void apply( const input & in, ParserState & state ) + static void apply(const input& in, ParserState & state) { DEBUG_PRINT_TOKEN(in.string()); state.current_group()->cpnd.sub_predicates.emplace_back(Predicate::Type::False); @@ -260,7 +260,7 @@ template<> struct action< false_pred > #define OPERATOR_ACTION(rule, oper) \ template<> struct action< rule > { \ - static void apply( const input & in, ParserState & state ) { \ + static void apply(const input& in, ParserState& state) { \ DEBUG_PRINT_TOKEN(in.string()); \ state.last_predicate()->cmpr.op = oper; }}; @@ -273,19 +273,19 @@ OPERATOR_ACTION(lt, Predicate::Operator::LessThan) OPERATOR_ACTION(begins, Predicate::Operator::BeginsWith) OPERATOR_ACTION(ends, Predicate::Operator::EndsWith) OPERATOR_ACTION(contains, Predicate::Operator::Contains) - + template<> struct action< case_insensitive > { - static void apply( const input & in, ParserState & state ) + static void apply(const input& in, ParserState & state) { DEBUG_PRINT_TOKEN(in.string()); state.last_predicate()->cmpr.option = Predicate::OperatorOption::CaseInsensitive; } }; - + template<> struct action< one< '(' > > { - static void apply( const input & in, ParserState & state ) + static void apply(const input&, ParserState & state) { DEBUG_PRINT_TOKEN(""); state.add_predicate_to_current_group(Predicate::Type::And); @@ -295,7 +295,7 @@ template<> struct action< one< '(' > > template<> struct action< group_pred > { - static void apply( const input & in, ParserState & state ) + static void apply(const input&, ParserState & state) { DEBUG_PRINT_TOKEN(""); state.group_stack.pop_back(); @@ -304,7 +304,7 @@ template<> struct action< group_pred > template<> struct action< not_pre > { - static void apply( const input & in, ParserState & state ) + static void apply(const input&, ParserState & state) { DEBUG_PRINT_TOKEN(""); state.negate_next = true; @@ -317,9 +317,9 @@ struct error_message_control : pegtl::normal< Rule > static const std::string error_message; template< typename Input, typename ... States > - static void raise( const Input & in, States && ... ) + static void raise(const Input& in, States&&...) { - throw pegtl::parse_error( error_message, in ); + throw pegtl::parse_error(error_message, in); } }; @@ -351,5 +351,3 @@ void analyze_grammar() } }} - - diff --git a/src/object-store/src/parser/query_builder.cpp b/src/object-store/src/parser/query_builder.cpp index 19d4883c..9a5b0268 100644 --- a/src/object-store/src/parser/query_builder.cpp +++ b/src/object-store/src/parser/query_builder.cpp @@ -27,10 +27,11 @@ #include #include -namespace realm { -namespace query_builder { +using namespace realm; using namespace parser; +using namespace query_builder; +namespace { template T stot(std::string const& s) { std::istringstream iss(s); @@ -268,12 +269,12 @@ void add_link_constraint_to_query(realm::Query &query, } } -auto link_argument(const PropertyExpression &propExpr, const parser::Expression &argExpr, Arguments &args) +auto link_argument(const PropertyExpression&, const parser::Expression &argExpr, Arguments &args) { return args.object_index_for_argument(stot(argExpr.s)); } -auto link_argument(const parser::Expression &argExpr, const PropertyExpression &propExpr, Arguments &args) +auto link_argument(const parser::Expression &argExpr, const PropertyExpression&, Arguments &args) { return args.object_index_for_argument(stot(argExpr.s)); } @@ -281,7 +282,7 @@ auto link_argument(const parser::Expression &argExpr, const PropertyExpression & template struct ColumnGetter { - static Columns convert(TableGetter&& table, const PropertyExpression & expr, Arguments &args) + static Columns convert(TableGetter&& table, const PropertyExpression& expr, Arguments&) { return table()->template column(expr.prop->table_column); } @@ -382,7 +383,7 @@ auto value_of_type_for_query(TableGetter&& tables, Value&& value, Arguments &arg } template -void do_add_comparison_to_query(Query &query, const Schema &schema, const ObjectSchema &object_schema, Predicate::Comparison cmp, +void do_add_comparison_to_query(Query &query, Predicate::Comparison cmp, const PropertyExpression &expr, A &lhs, B &rhs, Arguments &args) { auto type = expr.prop->type; @@ -425,7 +426,7 @@ void do_add_comparison_to_query(Query &query, const Schema &schema, const Object } template -void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const PropertyExpression &expr, Arguments &args) +void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const PropertyExpression &expr) { Columns column = expr.table_getter()->template column(expr.prop->table_column); switch (op) { @@ -441,7 +442,7 @@ void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const } template<> -void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const PropertyExpression &expr, Arguments &args) +void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const PropertyExpression &expr) { precondition(expr.indexes.empty(), "KeyPath queries not supported for data comparisons."); Columns column = expr.table_getter()->template column(expr.prop->table_column); @@ -458,7 +459,7 @@ void do_add_null_comparison_to_query(Query &query, Predicate::Operator o } template<> -void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const PropertyExpression &expr, Arguments &args) +void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const PropertyExpression &expr) { precondition(expr.indexes.empty(), "KeyPath queries not supported for object comparisons."); switch (op) { @@ -473,40 +474,38 @@ void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, } } -void do_add_null_comparison_to_query(Query &query, const Schema &schema, const ObjectSchema &object_schema, Predicate::Comparison cmp, - const PropertyExpression &expr, Arguments &args) +void do_add_null_comparison_to_query(Query &query, Predicate::Comparison cmp, const PropertyExpression &expr) { auto type = expr.prop->type; switch (type) { case realm::PropertyType::Bool: - do_add_null_comparison_to_query(query, cmp.op, expr, args); + do_add_null_comparison_to_query(query, cmp.op, expr); break; case realm::PropertyType::Date: - do_add_null_comparison_to_query(query, cmp.op, expr, args); + do_add_null_comparison_to_query(query, cmp.op, expr); break; case realm::PropertyType::Double: - do_add_null_comparison_to_query(query, cmp.op, expr, args); + do_add_null_comparison_to_query(query, cmp.op, expr); break; case realm::PropertyType::Float: - do_add_null_comparison_to_query(query, cmp.op, expr, args); + do_add_null_comparison_to_query(query, cmp.op, expr); break; case realm::PropertyType::Int: - do_add_null_comparison_to_query(query, cmp.op, expr, args); + do_add_null_comparison_to_query(query, cmp.op, expr); break; case realm::PropertyType::String: - do_add_null_comparison_to_query(query, cmp.op, expr, args); + do_add_null_comparison_to_query(query, cmp.op, expr); break; case realm::PropertyType::Data: - do_add_null_comparison_to_query(query, cmp.op, expr, args); + do_add_null_comparison_to_query(query, cmp.op, expr); break; case realm::PropertyType::Object: - do_add_null_comparison_to_query(query, cmp.op, expr, args); + do_add_null_comparison_to_query(query, cmp.op, expr); break; case realm::PropertyType::Array: throw std::runtime_error("Comparing Lists to 'null' is not supported"); - default: { - throw std::runtime_error(std::string("Object type ") + string_for_property_type(type) + " not supported"); - } + default: + throw std::runtime_error(util::format("Object type '%1' not supported", string_for_property_type(type))); } } @@ -528,19 +527,19 @@ void add_comparison_to_query(Query &query, const Predicate &pred, Arguments &arg if (t0 == parser::Expression::Type::KeyPath && t1 != parser::Expression::Type::KeyPath) { PropertyExpression expr(query, schema, object_schema, cmpr.expr[0].s); if (expression_is_null(cmpr.expr[1], args)) { - do_add_null_comparison_to_query(query, schema, *object_schema, cmpr, expr, args); + do_add_null_comparison_to_query(query, cmpr, expr); } else { - do_add_comparison_to_query(query, schema, *object_schema, cmpr, expr, expr, cmpr.expr[1], args); + do_add_comparison_to_query(query, cmpr, expr, expr, cmpr.expr[1], args); } } else if (t0 != parser::Expression::Type::KeyPath && t1 == parser::Expression::Type::KeyPath) { PropertyExpression expr(query, schema, object_schema, cmpr.expr[1].s); if (expression_is_null(cmpr.expr[0], args)) { - do_add_null_comparison_to_query(query, schema, *object_schema, cmpr, expr, args); + do_add_null_comparison_to_query(query, cmpr, expr); } else { - do_add_comparison_to_query(query, schema, *object_schema, cmpr, expr, cmpr.expr[0], expr, args); + do_add_comparison_to_query(query, cmpr, expr, cmpr.expr[0], expr, args); } } else { @@ -594,6 +593,10 @@ void update_query_with_predicate(Query &query, const Predicate &pred, Arguments throw std::runtime_error("Invalid predicate type"); } } +} // anonymous namespace + +namespace realm { +namespace query_builder { void apply_predicate(Query &query, const Predicate &predicate, Arguments &arguments, const Schema &schema, const std::string &objectType) { @@ -604,4 +607,5 @@ void apply_predicate(Query &query, const Predicate &predicate, Arguments &argume precondition(validateMessage.empty(), validateMessage.c_str()); } -}} +} +} diff --git a/src/object-store/tests/list.cpp b/src/object-store/tests/list.cpp index 4495762a..14ef80b3 100644 --- a/src/object-store/tests/list.cpp +++ b/src/object-store/tests/list.cpp @@ -72,7 +72,7 @@ TEST_CASE("list") { }; auto require_change = [&] { - auto token = lst.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) { + auto token = lst.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) { change = c; }); advance_and_notify(*r); @@ -81,7 +81,7 @@ TEST_CASE("list") { auto require_no_change = [&] { bool first = true; - auto token = lst.add_notification_callback([&, first](CollectionChangeSet c, std::exception_ptr err) mutable { + auto token = lst.add_notification_callback([&, first](CollectionChangeSet, std::exception_ptr) mutable { REQUIRE(first); first = false; }); diff --git a/src/object-store/tests/results.cpp b/src/object-store/tests/results.cpp index 001a144a..a384a785 100644 --- a/src/object-store/tests/results.cpp +++ b/src/object-store/tests/results.cpp @@ -549,7 +549,7 @@ TEST_CASE("[results] notifications after move") { auto results = std::make_unique(r, *config.schema->find("object"), *table); int notification_calls = 0; - auto token = results->add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) { + auto token = results->add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE_FALSE(err); ++notification_calls; }); diff --git a/src/object-store/tests/transaction_log_parsing.cpp b/src/object-store/tests/transaction_log_parsing.cpp index 4ff97415..bf4d71fa 100644 --- a/src/object-store/tests/transaction_log_parsing.cpp +++ b/src/object-store/tests/transaction_log_parsing.cpp @@ -59,7 +59,7 @@ private: Group const& m_group; LinkViewRef m_linkview; - std::vector m_initial; + std::vector m_initial; void validate(CollectionChangeSet const& info) {