From f00eb4f52d5f1b58315afffe6f03890a2f348de8 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 12 Jul 2016 16:38:39 -0700 Subject: [PATCH] Enable clang's warning about implicit fallthrough. --- src/object-store/CMake/CompilerFlags.cmake | 1 + src/object-store/src/CMakeLists.txt | 1 + src/object-store/src/parser/query_builder.cpp | 4 ++- src/object-store/src/results.cpp | 13 +------ src/object-store/src/util/compiler.hpp | 34 +++++++++++++++++++ 5 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 src/object-store/src/util/compiler.hpp diff --git a/src/object-store/CMake/CompilerFlags.cmake b/src/object-store/CMake/CompilerFlags.cmake index ebde76d1..be24ea56 100644 --- a/src/object-store/CMake/CompilerFlags.cmake +++ b/src/object-store/CMake/CompilerFlags.cmake @@ -25,6 +25,7 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") -Wmissing-prototypes -Wnewline-eof -Wshorten-64-to-32 + -Wimplicit-fallthrough ) endif() diff --git a/src/object-store/src/CMakeLists.txt b/src/object-store/src/CMakeLists.txt index 13cfc856..19c5f766 100644 --- a/src/object-store/src/CMakeLists.txt +++ b/src/object-store/src/CMakeLists.txt @@ -40,6 +40,7 @@ set(HEADERS parser/parser.hpp parser/query_builder.hpp util/atomic_shared_ptr.hpp + util/compiler.hpp util/format.hpp util/thread_id.hpp util/thread_local.hpp) diff --git a/src/object-store/src/parser/query_builder.cpp b/src/object-store/src/parser/query_builder.cpp index 9a5b0268..72c42e2e 100644 --- a/src/object-store/src/parser/query_builder.cpp +++ b/src/object-store/src/parser/query_builder.cpp @@ -21,6 +21,7 @@ #include "object_store.hpp" #include "schema.hpp" +#include "util/compiler.hpp" #include "util/format.hpp" #include @@ -259,6 +260,7 @@ void add_link_constraint_to_query(realm::Query &query, switch (op) { case Predicate::Operator::NotEqual: query.Not(); + REALM_FALLTHROUGH; case Predicate::Operator::Equal: { size_t col = prop_expr.prop->table_column; query.links_to(col, query.get_table()->get_link_target(col)->get(row_index)); @@ -464,8 +466,8 @@ void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, precondition(expr.indexes.empty(), "KeyPath queries not supported for object comparisons."); switch (op) { case Predicate::Operator::NotEqual: - // for not equal we negate the query and then fallthrough query.Not(); + REALM_FALLTHROUGH; case Predicate::Operator::Equal: query.and_query(query.get_table()->column(expr.prop->table_column).is_null()); break; diff --git a/src/object-store/src/results.cpp b/src/object-store/src/results.cpp index b18d712d..2cdb1bba 100644 --- a/src/object-store/src/results.cpp +++ b/src/object-store/src/results.cpp @@ -23,23 +23,12 @@ #include "object_schema.hpp" #include "object_store.hpp" #include "util/format.hpp" +#include "util/compiler.hpp" #include using namespace realm; -#ifdef __has_cpp_attribute -#define REALM_HAS_CCP_ATTRIBUTE(attr) __has_cpp_attribute(attr) -#else -#define REALM_HAS_CCP_ATTRIBUTE(attr) 0 -#endif - -#if REALM_HAS_CCP_ATTRIBUTE(clang::fallthrough) -#define REALM_FALLTHROUGH [[clang::fallthrough]] -#else -#define REALM_FALLTHROUGH -#endif - Results::Results() = default; Results::~Results() = default; diff --git a/src/object-store/src/util/compiler.hpp b/src/object-store/src/util/compiler.hpp new file mode 100644 index 00000000..581cb7bc --- /dev/null +++ b/src/object-store/src/util/compiler.hpp @@ -0,0 +1,34 @@ +//////////////////////////////////////////////////////////////////////////// +// +// Copyright 2015 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////// + +#ifndef REALM_UTIL_COMPILER_HPP +#define REALM_UTIL_COMPILER_HPP + +#ifdef __has_cpp_attribute +#define REALM_HAS_CCP_ATTRIBUTE(attr) __has_cpp_attribute(attr) +#else +#define REALM_HAS_CCP_ATTRIBUTE(attr) 0 +#endif + +#if REALM_HAS_CCP_ATTRIBUTE(clang::fallthrough) +#define REALM_FALLTHROUGH [[clang::fallthrough]] +#else +#define REALM_FALLTHROUGH +#endif + +#endif // REALM_UTIL_COMPILER_HPP