diff --git a/src/core/include/megbrain/common.h b/src/core/include/megbrain/common.h index af32f04efbb0c963490884c95234efe8a8dc2745..49f5d930491c35877172a21ee2d2e60263bba391 100644 --- a/src/core/include/megbrain/common.h +++ b/src/core/include/megbrain/common.h @@ -48,6 +48,13 @@ namespace mgb { //! warn if result of a function is not used #define MGB_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#if __cplusplus >= 201703L || __clang_major__ >= 4 +#define MGB_FALLTHRU [[fallthrough]]; +#elif __GNUC__ >= 7 +#define MGB_FALLTHRU __attribute__((fallthrough)); +#else +#define MGB_FALLTHRU +#endif /* ================ exception and assertion ================ */ diff --git a/src/serialization/impl/serializer.cpp b/src/serialization/impl/serializer.cpp index e5375d72348b3b61e7fbae8e8f60663eadf647e8..76d1495f21771ddd312eb269e4cfd89b139a824f 100644 --- a/src/serialization/impl/serializer.cpp +++ b/src/serialization/impl/serializer.cpp @@ -53,10 +53,11 @@ bool GraphDumper::should_remove_in_dump(cg::OperatorNodeBase *opr) { std::unique_ptr GraphDumper::make(std::unique_ptr file, GraphDumpFormat format) { switch (format) { -#if MGB_ENABLE_FBS_SERIALIZATION case GraphDumpFormat::FLATBUFFERS: +#if MGB_ENABLE_FBS_SERIALIZATION return make_fbs_dumper(std::move(file)); #endif + MGB_FALLTHRU default: mgb_throw(SerializationError, "unsupported serialization format requested"); @@ -66,10 +67,11 @@ std::unique_ptr GraphDumper::make(std::unique_ptr file, std::unique_ptr GraphLoader::make(std::unique_ptr file, GraphDumpFormat format) { switch (format) { -#if MGB_ENABLE_FBS_SERIALIZATION case GraphDumpFormat::FLATBUFFERS: +#if MGB_ENABLE_FBS_SERIALIZATION return make_fbs_loader(std::move(file)); #endif + MGB_FALLTHRU default: mgb_throw(SerializationError, "unsupported serialization format requested"); diff --git a/src/serialization/include/megbrain/serialization/opr_load_dump.h b/src/serialization/include/megbrain/serialization/opr_load_dump.h index 7d8f4f5f66461d284c61da2afc400ed145a69842..84258ce2b5da135f6a283a2f2bef20a4ead43a3f 100644 --- a/src/serialization/include/megbrain/serialization/opr_load_dump.h +++ b/src/serialization/include/megbrain/serialization/opr_load_dump.h @@ -29,9 +29,7 @@ struct OperatorParamTraits; enum class SerializationFormat { RAW_POD, -#if MGB_ENABLE_FBS_SERIALIZATION FLATBUFFERS, -#endif }; //! context for serializing a single operator @@ -162,12 +160,12 @@ void OprDumpContext::write_param(const Param& p) { case SerializationFormat::RAW_POD: static_cast(this)->write_param(p); break; -#if MGB_ENABLE_FBS_SERIALIZATION case SerializationFormat::FLATBUFFERS: +#if MGB_ENABLE_FBS_SERIALIZATION static_cast(this)->write_param( p, fbs::SupportFlatBuffersSerialization{}); - break; #endif + break; } } @@ -322,11 +320,13 @@ Param OprLoadContext::read_param() { case SerializationFormat::RAW_POD: return static_cast(this) ->read_param(); -#if MGB_ENABLE_FBS_SERIALIZATION case SerializationFormat::FLATBUFFERS: +#if MGB_ENABLE_FBS_SERIALIZATION return static_cast(this) ->read_param( fbs::SupportFlatBuffersSerialization{}); +#else + mgb_trap(); #endif } mgb_assert(0);