summaryrefslogtreecommitdiffstats
path: root/libdimension/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-06-24 16:21:58 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-06-24 16:22:31 -0400
commit537b7695c26b9ad83ccc13b68c78a2fb27545d7e (patch)
treea801d360354343b92600df3e3eb255ff87ab8487 /libdimension/dimension
parent77237a2e22acfc3f8a028cd1a4d63b602cbbf45e (diff)
downloaddimension-537b7695c26b9ad83ccc13b68c78a2fb27545d7e.tar.xz
Fix some warnings found by clang.
Diffstat (limited to 'libdimension/dimension')
-rw-r--r--libdimension/dimension/compiler.h86
-rw-r--r--libdimension/dimension/error.h27
2 files changed, 89 insertions, 24 deletions
diff --git a/libdimension/dimension/compiler.h b/libdimension/dimension/compiler.h
index 3d392b5..af3f4c8 100644
--- a/libdimension/dimension/compiler.h
+++ b/libdimension/dimension/compiler.h
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2009-2010 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Library. *
* *
@@ -24,18 +24,70 @@
*/
/**
+ * @internal
+ * @def DMNSN_C_VERSION
+ * The C version according to \p __STDC_VERSION__ if available, otherwise 0.
+ */
+#ifdef __STDC_VERSION__
+ #define DMNSN_C_VERSION __STDC_VERSION__
+#else
+ #define DMNSN_C_VERSION 0L
+#endif
+
+/**
+ * @internal
+ * @def DMNSN_CXX_VERSION
+ * The C++ version according to \p __cplusplus if available, otherwise 0.
+ */
+#ifdef __cplusplus
+ #define DMNSN_CXX_VERSION __cplusplus
+#else
+ #define DMNSN_CXX_VERSION 0L
+#endif
+
+/**
+ * @internal
+ * Whether we're being compiled as C++.
+ */
+#define DMNSN_CXX (DMNSN_CXX_VERSION > 0)
+
+/**
+ * @internal
+ * Whether C++11 features are supported.
+ */
+#define DMNSN_CXX11 (DMNSN_CXX_VERSION >= 201103L)
+
+/**
+ * @internal
+ * Whether C99 features are supported.
+ */
+#define DMNSN_C99 (DMNSN_C_VERSION >= 199901L || DMNSN_CXX11)
+
+/**
+ * @internal
+ * Whether C11 features are supported.
+ */
+#define DMNSN_C11 (DMNSN_C_VERSION >= 201112L)
+
+/**
+ * @internal
+ * Whether GNU C features are supported.
+ */
+#define DMNSN_GNUC defined(__GNUC__)
+
+/**
* @def DMNSN_INLINE
* A portable inline specifier. Expands to the correct method of declaring
* inline functions for the version of C you are using.
*/
#ifndef DMNSN_INLINE
- #ifdef __cplusplus
+ #if DMNSN_CXX
/* C++ inline semantics */
#define DMNSN_INLINE inline
- #elif __STDC_VERSION__ >= 199901L
+ #elif DMNSN_C99
/* C99 inline semantics */
#define DMNSN_INLINE inline
- #elif defined(__GNUC__)
+ #elif DMNSN_GNUC
/* GCC inline semantics */
#define DMNSN_INLINE __extension__ extern __inline__
#else
@@ -46,13 +98,27 @@
#endif
/**
+ * @def DMNSN_NORETURN
+ * A portable noreturn attribute.
+ */
+#if DMNSN_CXX11
+ #define DMNSN_NORETURN [[noreturn]] void
+#elif DMNSN_C11
+ #define DMNSN_NORETURN _Noreturn void
+#elif DMNSN_GNUC
+ #define DMNSN_NORETURN __attribute__((noreturn)) void
+#else
+ #define DMNSN_NORETURN void
+#endif
+
+/**
* @internal
* @def DMNSN_FUNC
* @brief Expands to the name of the current function
*/
-#ifdef __GNUC__
+#if DMNSN_GNUC
#define DMNSN_FUNC __PRETTY_FUNCTION__
-#elif __STDC_VERSION__ >= 199901L
+#elif DMNSN_C99
#define DMNSN_FUNC __func__
#else
#define DMNSN_FUNC "<unknown function>"
@@ -62,14 +128,8 @@
* @internal
* An unreachable statement.
*/
-#ifdef __GNUC__
+#if DMNSN_GNUC
#define DMNSN_UNREACHABLE() __builtin_unreachable()
#else
#define DMNSN_UNREACHABLE() ((void)0)
#endif
-
-/**
- * @internal
- * Whether C99 features are supported.
- */
-#define DMNSN_C99 (__STDC_VERSION__ >= 199901L || __cplusplus >= 201103L)
diff --git a/libdimension/dimension/error.h b/libdimension/dimension/error.h
index f07261e..0561b8a 100644
--- a/libdimension/dimension/error.h
+++ b/libdimension/dimension/error.h
@@ -32,18 +32,15 @@
* Report a warning.
* @param[in] str A string to print explaining the warning.
*/
-#define dmnsn_warning(str) \
- dmnsn_report_error(false, DMNSN_FUNC, __FILE__, __LINE__, str)
+#define dmnsn_warning(str) \
+ dmnsn_report_warning(DMNSN_FUNC, __FILE__, __LINE__, str)
/**
* Report an error.
* @param[in] str A string to print explaining the error.
*/
-#define dmnsn_error(str) \
- do { \
- dmnsn_report_error(true, DMNSN_FUNC, __FILE__, __LINE__, str); \
- DMNSN_UNREACHABLE(); \
- } while (0)
+#define dmnsn_error(str) \
+ dmnsn_report_error(DMNSN_FUNC, __FILE__, __LINE__, str)
/**
* @def dmnsn_assert
@@ -75,15 +72,23 @@
/**
* @internal
- * Called by dmnsn_warning() and dmnsn_error(); don't call directly.
- * @param[in] die Whether the error is fatal.
+ * Called by dmnsn_warning(); don't call directly.
* @param[in] func The name of the function where the error originated.
* @param[in] file The file where the error originated.
* @param[in] line The line number where the error originated.
* @param[in] str A string describing the error.
*/
-void dmnsn_report_error(bool die, const char *func, const char *file,
- unsigned int line, const char *str);
+void dmnsn_report_warning(const char *func, const char *file, unsigned int line, const char *str);
+
+/**
+ * @internal
+ * Called by dmnsn_error(); don't call directly.
+ * @param[in] func The name of the function where the error originated.
+ * @param[in] file The file where the error originated.
+ * @param[in] line The line number where the error originated.
+ * @param[in] str A string describing the error.
+ */
+DMNSN_NORETURN dmnsn_report_error(const char *func, const char *file, unsigned int line, const char *str);
/**
* Treat warnings as errors.