From 45be91c0e37cbd8131afe0b1dec468ba61e5e52c Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 2 Aug 2015 18:30:25 -0700 Subject: [PATCH] Add two new compiler feature tests --- Sources/Plasma/CoreLib/HeadSpin.h | 16 ++++++++++++ .../PubUtilLib/plGImage/plDynamicTextMap.h | 6 ++--- .../PubUtilLib/plNetClient/plNetClientMgr.h | 4 +-- .../PubUtilLib/plStatusLog/plStatusLog.h | 2 +- .../Tools/plFontConverter/plFontConverter.cpp | 6 ++--- .../Tools/plLocalizationEditor/plAddDlgs.cpp | 2 +- Sources/Tools/plResBrowser/plResBrowser.h | 5 ++-- cmake/CompilerChecks.cmake | 20 ++++++++------ cmake/check_noexcept.cpp | 7 +++++ cmake/check_override.cpp | 26 +++++++++++++++++++ cmake/hsCompilerSpecific.h.cmake | 2 ++ 11 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 cmake/check_noexcept.cpp create mode 100644 cmake/check_override.cpp diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 98de089a..c31d9876 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -130,6 +130,22 @@ typedef int32_t hsError; # define hsDeprecated(message) #endif +#ifdef HAVE_OVERRIDE +# define HS_OVERRIDE override +# define HS_FINAL final +#else +# define HS_OVERRIDE +# define HS_FINAL +#endif + +#ifdef HAVE_NOEXCEPT +# define HS_NOEXCEPT noexcept +# define HS_NOEXCEPT_IF(cond) noexcept(cond) +#else +# define HS_NOEXCEPT throw() +# define HS_NOEXCEPT_IF(cond) +#endif + //====================================== // Endian swap funcitions //====================================== diff --git a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h index 01bc12a1..8069d4c6 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h @@ -130,9 +130,9 @@ class plDynamicTextMap : public plMipmap virtual uint8_t GetNumLevels( void ) const { return 1; } - void Colorize() override { } - plMipmap *Clone() const override; - void CopyFrom(const plMipmap *source) override; + void Colorize() HS_OVERRIDE { } + plMipmap *Clone() const HS_OVERRIDE; + void CopyFrom(const plMipmap *source) HS_OVERRIDE; /// Operations to perform on the text block diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h index 0e13a7b5..a9cb101c 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h @@ -237,7 +237,7 @@ private: int ISendGameMessage(plMessage* msg); void IDisableNet (); - void ICreateStatusLog() const override; + void ICreateStatusLog() const HS_OVERRIDE; public: plNetClientMgr(); @@ -265,7 +265,7 @@ public: void SendApplyAvatarCustomizationsMsg(const plKey msgReceiver, bool netPropagate=true, bool localPropagate=true); // plLoggable - bool Log(const plString& str) const override; + bool Log(const plString& str) const HS_OVERRIDE; // setters void SetIniAuthServer(const char * value) { fIniAuthServer=value;} diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h index 991765ad..ddf356a9 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h @@ -159,7 +159,7 @@ class plStatusLog : public plLog ~plStatusLog(); - bool AddLine(const plString& line) override; + bool AddLine(const plString& line) HS_OVERRIDE; bool AddLine( const char *line, uint32_t color = kWhite ); diff --git a/Sources/Tools/plFontConverter/plFontConverter.cpp b/Sources/Tools/plFontConverter/plFontConverter.cpp index 8dec0c85..381cc14c 100644 --- a/Sources/Tools/plFontConverter/plFontConverter.cpp +++ b/Sources/Tools/plFontConverter/plFontConverter.cpp @@ -350,12 +350,12 @@ class plMyBDFCallback : public plBDFConvertCallback public: plMyBDFCallback(QWidget *parent) : fProgress(parent) { } - virtual void NumChars(uint16_t chars) override + void NumChars(uint16_t chars) HS_OVERRIDE { fProgress.SetRange(chars); } - virtual void CharDone() override + void CharDone() HS_OVERRIDE { fPoint++; fProgress.SetValue(fPoint); @@ -498,7 +498,7 @@ class NumListValidator : public QValidator public: NumListValidator(QObject *parent = nullptr) : QValidator(parent) { } - virtual State validate(QString &input, int &pos) const override + State validate(QString &input, int &pos) const HS_OVERRIDE { for (int ch = 0; ch < input.size(); ++ch) { diff --git a/Sources/Tools/plLocalizationEditor/plAddDlgs.cpp b/Sources/Tools/plLocalizationEditor/plAddDlgs.cpp index f9180642..216084d7 100644 --- a/Sources/Tools/plLocalizationEditor/plAddDlgs.cpp +++ b/Sources/Tools/plLocalizationEditor/plAddDlgs.cpp @@ -59,7 +59,7 @@ class AlphaNumericValidator : public QValidator public: AlphaNumericValidator(QObject *parent = nullptr) : QValidator(parent) { } - virtual State validate(QString &input, int &pos) const override + State validate(QString &input, int &pos) const HS_OVERRIDE { for (int ch = 0; ch < input.size(); ++ch) { diff --git a/Sources/Tools/plResBrowser/plResBrowser.h b/Sources/Tools/plResBrowser/plResBrowser.h index 9372db17..1cd2c783 100644 --- a/Sources/Tools/plResBrowser/plResBrowser.h +++ b/Sources/Tools/plResBrowser/plResBrowser.h @@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define _plResBrowser_h #include +#include "HeadSpin.h" class plResBrowser : public QMainWindow { @@ -55,8 +56,8 @@ public: void SetWindowTitle(const QString &title); protected: - virtual void dragEnterEvent(QDragEnterEvent *event) override; - virtual void dropEvent(QDropEvent *event) override; + void dragEnterEvent(QDragEnterEvent *event) HS_OVERRIDE; + void dropEvent(QDropEvent *event) HS_OVERRIDE; private slots: void OpenFile(); diff --git a/cmake/CompilerChecks.cmake b/cmake/CompilerChecks.cmake index 11be0d74..6248e38f 100644 --- a/cmake/CompilerChecks.cmake +++ b/cmake/CompilerChecks.cmake @@ -40,8 +40,7 @@ endif() # Check for CPUID headers try_compile(HAVE_CPUID ${PROJECT_BINARY_DIR} - ${PROJECT_SOURCE_DIR}/cmake/check_cpuid.cpp - OUTPUT_VARIABLE OUTPUT) + ${PROJECT_SOURCE_DIR}/cmake/check_cpuid.cpp) if(HAVE_CPUID) message("CPUID header found -- using hardware math acceleration when available") else() @@ -51,17 +50,22 @@ endif() # Look for a supported "deprecated" attribute specifier. try_compile(HAVE_CXX14_DEPRECATED_ATTR ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/check_deprecated_attribute.cpp - COMPILE_DEFINITIONS -DTRY_ATTRIBUTE - OUTPUT_VARIABLE OUTPUT) + COMPILE_DEFINITIONS -DTRY_ATTRIBUTE) try_compile(HAVE_GCC_DEPRECATED_ATTR ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/check_deprecated_attribute.cpp - COMPILE_DEFINITIONS -DTRY_GCC_ATTR - OUTPUT_VARIABLE OUTPUT) + COMPILE_DEFINITIONS -DTRY_GCC_ATTR) # Look for C++11 constexpr support try_compile(HAVE_CONSTEXPR ${PROJECT_BINARY_DIR} - ${PROJECT_SOURCE_DIR}/cmake/check_constexpr.cpp - OUTPUT_VARIABLE OUTPUT) + ${PROJECT_SOURCE_DIR}/cmake/check_constexpr.cpp) + +# Look for C++11 override/final specifiers +try_compile(HAVE_OVERRIDE ${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/cmake/check_override.cpp) + +# Look for C++11 noexcept specifier +try_compile(HAVE_NOEXCEPT ${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/cmake/check_noexcept.cpp) configure_file(${PROJECT_SOURCE_DIR}/cmake/hsCompilerSpecific.h.cmake ${PROJECT_BINARY_DIR}/hsCompilerSpecific.h) diff --git a/cmake/check_noexcept.cpp b/cmake/check_noexcept.cpp new file mode 100644 index 00000000..a1c5691f --- /dev/null +++ b/cmake/check_noexcept.cpp @@ -0,0 +1,7 @@ +void doesnt_throw() noexcept { } + +int main(int, char **) +{ + doesnt_throw(); + return 0; +} diff --git a/cmake/check_override.cpp b/cmake/check_override.cpp new file mode 100644 index 00000000..b6c70f66 --- /dev/null +++ b/cmake/check_override.cpp @@ -0,0 +1,26 @@ +class Base +{ +public: + virtual ~Base() { } + virtual void virtual_function() = 0; +}; + +class Override : public Base +{ +public: + void virtual_function() override { } +}; + +class Final : public Override +{ +public: + void virtual_function() final { } +}; + +int main(int, char **) +{ + Final klass; + klass.virtual_function(); + + return 0; +} diff --git a/cmake/hsCompilerSpecific.h.cmake b/cmake/hsCompilerSpecific.h.cmake index 242c4cf1..665e5500 100644 --- a/cmake/hsCompilerSpecific.h.cmake +++ b/cmake/hsCompilerSpecific.h.cmake @@ -52,5 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #cmakedefine HAVE_GCC_DEPRECATED_ATTR #cmakedefine HAVE_CONSTEXPR +#cmakedefine HAVE_OVERRIDE +#cmakedefine HAVE_NOEXCEPT #endif