From f732a587d710150417c32b19586ce8881a80f4bd Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 3 Jun 2019 14:13:12 +0200 Subject: [PATCH] Replace NO_RETURN with [[noreturn]] standard attribute --- include/fc/exception/exception.hpp | 14 +++++++------- include/fc/io/datastream.hpp | 3 +-- include/fc/utility.hpp | 13 ------------- src/exception.cpp | 6 +++--- src/io/datastream.cpp | 2 +- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index e5b54a4..e61e92f 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -106,7 +106,7 @@ namespace fc * * @note does not return. */ - virtual NO_RETURN void dynamic_rethrow_exception()const; + [[noreturn]] virtual void dynamic_rethrow_exception()const; /** * This is equivalent to: @@ -155,7 +155,7 @@ namespace fc std::exception_ptr get_inner_exception()const; - virtual NO_RETURN void dynamic_rethrow_exception()const; + [[noreturn]] virtual void dynamic_rethrow_exception()const; virtual std::shared_ptr dynamic_copy_exception()const; private: std::exception_ptr _inner; @@ -179,13 +179,13 @@ namespace fc public: struct base_exception_builder { - virtual NO_RETURN void rethrow( const exception& e )const = 0; + [[noreturn]] virtual void rethrow( const exception& e )const = 0; }; template struct exception_builder : public base_exception_builder { - virtual NO_RETURN void rethrow( const exception& e )const override + [[noreturn]] virtual void rethrow( const exception& e )const override { throw T( e ); } @@ -201,7 +201,7 @@ namespace fc _registered_exceptions[T::code_value] = &builder; } - void NO_RETURN rethrow( const exception& e )const; + [[noreturn]] void rethrow( const exception& e )const; static exception_factory& instance() { @@ -243,7 +243,7 @@ namespace fc explicit TYPE();\ \ virtual std::shared_ptr dynamic_copy_exception()const;\ - virtual NO_RETURN void dynamic_rethrow_exception()const; \ + [[noreturn]] virtual void dynamic_rethrow_exception()const; \ }; #define FC_IMPLEMENT_DERIVED_EXCEPTION( TYPE, BASE, CODE, WHAT ) \ @@ -269,7 +269,7 @@ namespace fc { \ return std::make_shared( *this ); \ } \ - NO_RETURN void TYPE::dynamic_rethrow_exception()const \ + [[noreturn]] void TYPE::dynamic_rethrow_exception()const \ { \ if( code() == CODE ) throw *this;\ else fc::exception::dynamic_rethrow_exception(); \ diff --git a/include/fc/io/datastream.hpp b/include/fc/io/datastream.hpp index 0bf36a1..87b432e 100644 --- a/include/fc/io/datastream.hpp +++ b/include/fc/io/datastream.hpp @@ -1,5 +1,4 @@ #pragma once -#include #include #include @@ -7,7 +6,7 @@ namespace fc { namespace detail { - NO_RETURN void throw_datastream_range_error( const char* file, size_t len, int64_t over ); + [[noreturn]] void throw_datastream_range_error( const char* file, size_t len, int64_t over ); } /** diff --git a/include/fc/utility.hpp b/include/fc/utility.hpp index ff3c604..ce46946 100644 --- a/include/fc/utility.hpp +++ b/include/fc/utility.hpp @@ -2,19 +2,6 @@ #include #include -#ifdef _MSC_VER -#pragma warning(disable: 4482) // nonstandard extension used enum Name::Val, standard in C++11 -#define NO_RETURN __declspec(noreturn) -#else -#define NO_RETURN __attribute__((noreturn)) -#endif - - -//namespace std { -// typedef decltype(sizeof(int)) size_t; -// typedef decltype(nullptr) nullptr_t; -//} - namespace fc { using std::size_t; diff --git a/src/exception.cpp b/src/exception.cpp index 79b2135..d3fadbb 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -96,7 +96,7 @@ namespace fc std::exception_ptr unhandled_exception::get_inner_exception()const { return _inner; } - NO_RETURN void unhandled_exception::dynamic_rethrow_exception()const + [[noreturn]] void unhandled_exception::dynamic_rethrow_exception()const { if( !(_inner == std::exception_ptr()) ) std::rethrow_exception( _inner ); else { fc::exception::dynamic_rethrow_exception(); } @@ -217,7 +217,7 @@ namespace fc return ss.str(); } - void NO_RETURN exception_factory::rethrow( const exception& e )const + [[noreturn]] void exception_factory::rethrow( const exception& e )const { auto itr = _registered_exceptions.find( e.code() ); if( itr != _registered_exceptions.end() ) @@ -229,7 +229,7 @@ namespace fc * the error code. This is used to propagate exception types * across conversions to/from JSON */ - NO_RETURN void exception::dynamic_rethrow_exception()const + [[noreturn]] void exception::dynamic_rethrow_exception()const { exception_factory::instance().rethrow( *this ); } diff --git a/src/io/datastream.cpp b/src/io/datastream.cpp index 69fda0d..5ece65f 100644 --- a/src/io/datastream.cpp +++ b/src/io/datastream.cpp @@ -1,7 +1,7 @@ #include #include -NO_RETURN void fc::detail::throw_datastream_range_error(char const* method, size_t len, int64_t over) +[[noreturn]] void fc::detail::throw_datastream_range_error(char const* method, size_t len, int64_t over) { FC_THROW_EXCEPTION( out_of_range_exception, "${method} datastream of length ${len} over by ${over}", ("method",std::string(method))("len",len)("over",over) ); }