build: detect override & final specifiers support
refs #2454
Change-Id: I274fec7c5b6348e8b688eda2f2e13d04984d61e4
diff --git a/.waf-tools/compiler-features.py b/.waf-tools/compiler-features.py
index 4bc9594..2500298 100644
--- a/.waf-tools/compiler-features.py
+++ b/.waf-tools/compiler-features.py
@@ -43,5 +43,33 @@
features='cxx', mandatory=True):
self.define('HAVE_CXX_FRIEND_TYPENAME_WRAPPER', 1)
+OVERRIDE = '''
+class Base
+{
+ virtual void
+ f(int a);
+};
+
+class Derived : public Base
+{
+ virtual void
+ f(int a) override;
+};
+
+class Final : public Derived
+{
+ virtual void
+ f(int a) final;
+};
+'''
+
+@conf
+def check_override(self):
+ if self.check_cxx(msg='Checking for override and final specifiers',
+ fragment=OVERRIDE,
+ features='cxx', mandatory=False):
+ self.define('HAVE_CXX_OVERRIDE_FINAL', 1)
+
def configure(conf):
conf.check_friend_typename()
+ conf.check_override()
diff --git a/src/common.hpp b/src/common.hpp
index aea3af3..1cf0c7b 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -44,6 +44,20 @@
#define NDN_CXX_PROTECTED_WITH_TESTS_ELSE_PRIVATE private
#endif
+/** \def NDN_CXX_DECL_OVERRIDE
+ * \brief expands to 'override' if compiler supports this feature, otherwise expands to nothing
+ */
+/** \def NDN_CXX_DECL_FINAL
+ * \brief expands to 'final' if compiler supports this feature, otherwise expands to nothing
+ */
+#ifdef NDN_CXX_HAVE_CXX_OVERRIDE_FINAL
+#define NDN_CXX_DECL_OVERRIDE override
+#define NDN_CXX_DECL_FINAL override
+#else
+#define NDN_CXX_DECL_OVERRIDE
+#define NDN_CXX_DECL_FINAL
+#endif
+
// require C++11
#if __cplusplus < 201103L && !defined(__GXX_EXPERIMENTAL_CXX0X__)
# error "ndn-cxx applications must be compiled using the C++11 standard"