From c86f703dcf6df51013b512afb8ea96e43c877980 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 7 Aug 2017 19:11:13 +0200 Subject: [PATCH] Some Windows compilation fixes + support for [[nodiscard]]. --- build/Lol (vs2015).sln | 5 ----- src/lol/base/features.h | 26 ++++++++++++++++++++++++-- src/lol/base/log.h | 14 ++++---------- src/lol/base/string.h | 24 +++++++++--------------- src/lol/math/real.h | 11 +++++++---- 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/build/Lol (vs2015).sln b/build/Lol (vs2015).sln index 7ecd0c1a..8cdeddd7 100644 --- a/build/Lol (vs2015).sln +++ b/build/Lol (vs2015).sln @@ -36,8 +36,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{1AFD58 msbuild\config-build.xml = msbuild\config-build.xml EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{3D341D8A-E400-4B1D-BC05-B5C35487D9B5}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "btphystest", "..\doc\samples\btphystest.vcxproj", "{EE203B88-44CF-4859-9D42-7A1F43FECB52}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "08_fbo", "..\doc\tutorial\08_fbo.vcxproj", "{BCEE0132-8E24-49BE-AFEB-96DAD14396BA}" @@ -320,7 +318,6 @@ Global {5A27FF18-A1EC-49BE-9455-415F1C701153} = {E4DFEBF9-C310-462F-9876-7EB59C1E4D4E} {D7F6C2CA-5A13-4FD0-8468-1833923E3EE3} = {E4DFEBF9-C310-462F-9876-7EB59C1E4D4E} {B1E10086-A1DA-401A-834D-969C9DBB5CC1} = {B6297FF2-63D0-41EE-BE13-EFF720C9B0FA} - {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} = {1AFD580B-98B8-4689-B661-38C41132C60E} {B92ABADC-45BE-4CC5-B724-9426053123A1} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} {7B083DA2-FE08-4F6D-BFDD-195D5C2783EB} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} {1C5B8702-290C-42DA-AA9E-671348F5B747} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} @@ -333,9 +330,7 @@ Global {6BF81B39-EDC2-4227-9982-C2D8ABEA95AF} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} {572E5B9C-7E19-489C-BD8A-E8401CFBBC47} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} - {E4DFEBF9-C310-462F-9876-7EB59C1E4D4E} = {1AFD580B-98B8-4689-B661-38C41132C60E} {F59FA82C-DDB9-4EE2-80AE-CB0E4C6567A4} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} - {B6297FF2-63D0-41EE-BE13-EFF720C9B0FA} = {1AFD580B-98B8-4689-B661-38C41132C60E} {81C83B42-D00A-4FA3-9A3D-80F9D46524BF} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} {31B96262-1C41-43B9-BA38-27AA385B05DB} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} EndGlobalSection diff --git a/src/lol/base/features.h b/src/lol/base/features.h index 65f5859e..bcb5e5bf 100644 --- a/src/lol/base/features.h +++ b/src/lol/base/features.h @@ -38,7 +38,7 @@ /* - * Check for C++11 features. + * Check for C++11 and later features. */ /* These features aren't necessarily supported by all compilers */ @@ -51,10 +51,13 @@ #undef LOL_FEATURE_CXX11_TEMPLATE_ALIASES #undef LOL_FEATURE_CXX11_SFINAE_FOR_CTORS +#undef LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD + /* Features supported by GCC */ #if defined __GNUC__ # define LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS 1 # define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1 +# define LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD 1 # if defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L # define LOL_FEATURE_CXX11_CONSTEXPR 1 # define LOL_FEATURE_CXX11_ISNAN 1 @@ -72,6 +75,7 @@ # define LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS 1 # define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1 # define LOL_FEATURE_CXX11_ARRAY_INITIALIZERS 1 +# define LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD 1 # if __has_feature(cxx_constexpr) # define LOL_FEATURE_CXX11_CONSTEXPR 1 # endif @@ -97,9 +101,27 @@ # endif /* Supported in VS 2015 but causes massive warning output */ # undef LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS - /* Still unsupported as of VS 2015 */ + /* Still unsupported as of VS 2015 (TODO: check VS2017) */ # undef LOL_FEATURE_CXX11_ARRAY_INITIALIZERS # undef LOL_FEATURE_CXX11_CONSTEXPR +# undef LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD +#endif + + +/* + * Define some attribute macros. + */ + +#ifdef __GNUC__ +# define LOL_ATTR_FORMAT(n, p) __attribute__((format(printf, n, p))) +#else +# define LOL_ATTR_FORMAT(n, p) +#endif + +#ifdef LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD +# define LOL_ATTR_NODISCARD [[nodiscard]] +#else +# define LOL_ATTR_NODISCARD /* */ #endif diff --git a/src/lol/base/log.h b/src/lol/base/log.h index 071db123..1a0cf0e8 100644 --- a/src/lol/base/log.h +++ b/src/lol/base/log.h @@ -27,16 +27,10 @@ namespace lol class msg { public: -#ifdef __GNUC__ -# define LOL_FMT_ATTR(n, p) __attribute__((format(printf, n, p))) -#else -# define LOL_FMT_ATTR(n, p) -#endif - static void debug(char const *format, ...) LOL_FMT_ATTR(1, 2); - static void info(char const *format, ...) LOL_FMT_ATTR(1, 2); - static void warn(char const *format, ...) LOL_FMT_ATTR(1, 2); - static void error(char const *format, ...) LOL_FMT_ATTR(1, 2); -#undef LOL_FMT_ATTR + static void debug(char const *format, ...) LOL_ATTR_FORMAT(1, 2); + static void info(char const *format, ...) LOL_ATTR_FORMAT(1, 2); + static void warn(char const *format, ...) LOL_ATTR_FORMAT(1, 2); + static void error(char const *format, ...) LOL_ATTR_FORMAT(1, 2); private: enum class MessageType diff --git a/src/lol/base/string.h b/src/lol/base/string.h index 1676e1f4..828ff021 100644 --- a/src/lol/base/string.h +++ b/src/lol/base/string.h @@ -34,13 +34,13 @@ private: typedef array super; public: - inline String() + inline LOL_ATTR_NODISCARD String() : super() { push('\0'); } - inline String(char const *str) + inline LOL_ATTR_NODISCARD String(char const *str) : super() { using namespace std; @@ -49,7 +49,7 @@ public: memcpy(&(*this)[0], str, count() + 1); } - inline String(char const *str, int item_count) + inline LOL_ATTR_NODISCARD String(char const *str, int item_count) : super() { using namespace std; @@ -59,7 +59,7 @@ public: ((super &)*this)[item_count] = '\0'; } - inline String(String const &s) + inline LOL_ATTR_NODISCARD String(String const &s) : super((super const &)s) { } @@ -268,13 +268,13 @@ public: return true; } - inline String operator +(String const &s) const + inline LOL_ATTR_NODISCARD String operator +(String const &s) const { String ret(*this); return ret += s; } - inline String operator +(char c) const + inline LOL_ATTR_NODISCARD String operator +(char c) const { String ret(*this); return ret += c; @@ -334,22 +334,16 @@ public: return res < 0; } -#ifdef __GNUC__ -# define LOL_FMT_ATTR(n, p) __attribute__((format(printf, n, p))) -#else -# define LOL_FMT_ATTR(n, p) -#endif - static String format(char const *format, ...) LOL_FMT_ATTR(1, 2); -#undef LOL_FMT_ATTR + static String format(char const *format, ...) LOL_ATTR_FORMAT(1, 2); static String vformat(char const *format, va_list ap); }; -inline String operator +(char c, String const &s) +inline LOL_ATTR_NODISCARD String operator +(char c, String const &s) { return String() + c + s; } -inline String operator +(char const *sz, String const &s) +inline LOL_ATTR_NODISCARD String operator +(char const *sz, String const &s) { return String(sz) + s; } diff --git a/src/lol/math/real.h b/src/lol/math/real.h index 8d5d22bd..acba690b 100644 --- a/src/lol/math/real.h +++ b/src/lol/math/real.h @@ -204,18 +204,21 @@ public: static Real const& R_MAX(); private: - uint32_t *m_mantissa; - uint32_t m_signexp; + typedef uint32_t bigit_t; + typedef uint32_t signexp_t; + + bigit_t *m_mantissa; + signexp_t m_signexp; public: /* XXX: changing this requires tuning real::fres (the number of * Newton-Raphson iterations) and real::print (the number of printed * digits) */ static int const BIGIT_COUNT = N; - static int const BIGIT_BITS = 8 * sizeof(*m_mantissa); + static int const BIGIT_BITS = 8 * sizeof(bigit_t); static int const TOTAL_BITS = BIGIT_COUNT * BIGIT_BITS; - static int const EXPONENT_BITS = 8 * sizeof(m_signexp) - 1; + static int const EXPONENT_BITS = 8 * sizeof(signexp_t) - 1; static int const EXPONENT_BIAS = (1 << (EXPONENT_BITS - 1)) - 1; };