From 23b0a7b1467e97576348640a286e109876d0c8ad Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 17 Oct 2014 19:24:53 +1100 Subject: [PATCH] remove annotations header The annotations were never particularly robust, and weren't used in many locations (or consistently). And we should be migrating to c++14 annotation syntax anyway. By focusing on writing them all locally we will be a little more standards compliant, and the attributes should be more visible. --- Makefile.am | 1 - annotations.hpp | 44 -------------------------------------------- debug.hpp | 20 +++++++++----------- io.hpp | 3 +-- maths.hpp | 18 ++++++++---------- net/except.hpp | 6 ++---- quaternion.hpp | 5 ++--- vector.hpp | 3 +-- 8 files changed, 23 insertions(+), 77 deletions(-) delete mode 100644 annotations.hpp diff --git a/Makefile.am b/Makefile.am index bc534c5c..6d72e7cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,6 @@ SUBDIRS = test ## Source definitions UTIL_FILES = \ - annotations.hpp \ backtrace.hpp \ bitwise.cpp \ bitwise.hpp \ diff --git a/annotations.hpp b/annotations.hpp deleted file mode 100644 index 75c28e3a..00000000 --- a/annotations.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of libgim. - * - * libgim is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * ligim is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with libgim. If not, see . - * - * Copyright 2010-2012 Danny Robson - */ - - -#ifndef __ANNOTATIONS_HPP -#define __ANNOTATIONS_HPP - -// Don't use the name 'noreturn' as it interferes with other headers which -// may use __attribute__((noreturn)) explicitly. -#define terminal __attribute__ ((noreturn)) - -#if GCC_VERSION >= 40601 -#define nonnull __attribute__ ((nonnull)) -#endif - -#define mustuse __attribute__ ((warn_unused_result)) - -#if GCC_VERSION >= 40601 -#define unused __attribute__ ((unused)) -#endif - -#define pure __attribute__ ((pure)) - -#define likely(X) (__builtin_expect((X), 1)) -#define unlikely(X) (__builtin_expect((X), 0)) - -#endif // __ANNOTATIONS_HPP - diff --git a/debug.hpp b/debug.hpp index 6f45f9b4..09094169 100644 --- a/debug.hpp +++ b/debug.hpp @@ -20,8 +20,6 @@ #ifndef __DEBUG_HPP #define __DEBUG_HPP - -#include "annotations.hpp" #include "maths.hpp" #include @@ -79,7 +77,7 @@ /////////////////////////////////////////////////////////////////////////////// #define _CHECK_META(C, SUCCESS, FAILURE) do { \ const auto __DEBUG_value = (C); \ - if (unlikely (!__DEBUG_value)) { \ + if (!__DEBUG_value) { \ std::cerr << PACKAGE << ": " \ << __FILE__ << ":" \ << __LINE__ << ": " \ @@ -221,7 +219,7 @@ catch (E) \ { caught = true; } \ \ - if (unlikely (!caught)) \ + if (!caught) \ panic ("expected exception: " #E); \ } while (0) @@ -248,19 +246,19 @@ class panic_error { }; -void panic (const std::string&) terminal; -void panic (void) terminal; +void panic [[noreturn]] (const std::string&); +void panic [[noreturn]] (void); /////////////////////////////////////////////////////////////////////////////// -void not_implemented (void) terminal; -void not_implemented (const char*) terminal; +void not_implemented [[noreturn]] (void); +void not_implemented [[noreturn]] (const char*); /////////////////////////////////////////////////////////////////////////////// -void unreachable (void) terminal; -void unreachable (const std::string&) terminal; -void unusual (void); +void unreachable [[noreturn]] (void); +void unreachable [[noreturn]] (const std::string&); +void unusual (void); /////////////////////////////////////////////////////////////////////////////// diff --git a/io.hpp b/io.hpp index 894040e3..dc2ec681 100644 --- a/io.hpp +++ b/io.hpp @@ -20,7 +20,6 @@ #ifndef __UTIL_IO_HPP #define __UTIL_IO_HPP -#include "annotations.hpp" #include "types.hpp" #include "memory.hpp" @@ -41,7 +40,7 @@ namespace util { /// Reads an entire file into memory. Caller frees the result. Guarantees a /// null trailing byte. std::unique_ptr - slurp (const boost::filesystem::path&) mustuse; + slurp [[gnu::warn_unused_result]] (const boost::filesystem::path&); void write (const boost::filesystem::path &, const char *data, size_t len); diff --git a/maths.hpp b/maths.hpp index 1c115b35..a3c8447d 100644 --- a/maths.hpp +++ b/maths.hpp @@ -20,8 +20,6 @@ #ifndef __MATHS_HPP #define __MATHS_HPP -#include "annotations.hpp" - #include #include @@ -33,42 +31,42 @@ pow2 (T value) template bool -is_pow2 (T value) pure; +is_pow2 [[gnu::pure]] (T value); template T -log2 (T val) pure; +log2 [[gnu::pure]] (T val); template T -log2up (T val) pure; +log2up [[gnu::pure]] (T val); template double -rootsquare (T a, T b) pure; +rootsquare [[gnu::pure]] (T a, T b); template typename std::common_type::type -align (T value, U size) pure; +align [[gnu::pure]] (T value, U size); template T -round_pow2 (T value) pure; +round_pow2 [[gnu::pure]] (T value); template bool -is_integer (const T& value) pure; +is_integer [[gnu::pure]] (const T& value); template unsigned -digits (const T& value) pure; +digits [[gnu::pure]] (const T& value); template diff --git a/net/except.hpp b/net/except.hpp index a5bafcaf..b88f1c6c 100644 --- a/net/except.hpp +++ b/net/except.hpp @@ -30,8 +30,6 @@ #include #include -#include "../annotations.hpp" - //----------------------------------------------------------------------------- namespace net { @@ -47,14 +45,14 @@ namespace net { /// Throw an error corresponding the a given code. Code must be a valid error code, /// not success otherwise the application will (at best) abort. static void - throw_code (int code) terminal; + throw_code [[noreturn]] (int code); /// Throw an error corresponding to the most recent error condition. This will check /// the current error condition in a platform agnostic manner, and pass on to /// throw_code(int). This should be used whenever an error has been detected, rather /// than the more normal try_code(errno) due to Windows error reporting quirks. static void - throw_code (void) terminal; + throw_code [[noreturn]] (void); static void try_code (int code); diff --git a/quaternion.hpp b/quaternion.hpp index 24f8e92d..66b99413 100644 --- a/quaternion.hpp +++ b/quaternion.hpp @@ -20,7 +20,6 @@ #ifndef __UTIL_QUATERNION_HPP #define __UTIL_QUATERNION_HPP -#include "annotations.hpp" #include "vector.hpp" namespace util { @@ -29,8 +28,8 @@ namespace util { static const quaternion IDENTITY; - static quaternion rotation (double radians, vector<3> axis) mustuse; - static quaternion rotation (vector<3> from, vector<3> to) mustuse; + static quaternion rotation (double radians, vector<3> axis); + static quaternion rotation (vector<3> from, vector<3> to); quaternion operator* (const quaternion&) const; }; diff --git a/vector.hpp b/vector.hpp index 7a773382..76d372a7 100644 --- a/vector.hpp +++ b/vector.hpp @@ -22,7 +22,6 @@ #include "json.hpp" #include "detail/coord.hpp" -#include "annotations.hpp" #include #include @@ -71,7 +70,7 @@ namespace util { double dot (const util::vector&) const; util::vector& normalise (void); - util::vector normalised (void) const mustuse; + util::vector normalised [[gnu::warn_unused_result]] (void) const; bool is_zero (void) const;