Revision: 16231
Author:   [email protected]
Date:     Tue Aug 20 06:51:58 2013 UTC
Log:      Add V8_FINAL and V8_OVERRIDE macros for C++11 final/override.

[email protected]

Review URL: https://codereview.chromium.org/22914019
http://code.google.com/p/v8/source/detail?r=16231

Modified:
 /branches/bleeding_edge/src/globals.h

=======================================
--- /branches/bleeding_edge/src/globals.h       Tue Aug 20 06:39:04 2013 UTC
+++ /branches/bleeding_edge/src/globals.h       Tue Aug 20 06:51:58 2013 UTC
@@ -328,6 +328,50 @@
 F FUNCTION_CAST(Address addr) {
   return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
 }
+
+
+// Compiler feature detection.
+#if defined(__clang__)
+
+// Compatibility with older clang versions.
+# ifndef __has_extension
+# define __has_extension __has_feature
+# endif
+
+# if __has_extension(cxx_override_control)
+#  define V8_HAVE_CXX11_FINAL
+#  define V8_HAVE_CXX11_OVERRIDE
+# endif
+
+#elif defined(__GNUC__)
+
+// g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality
+// without warnings (functionality used by the macros below).  These modes
+// are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or,
+// more standardly, by checking whether __cplusplus has a C++11 or greater
+// value. Current versions of g++ do not correctly set __cplusplus, so we check
+// both for forward compatibility.
+# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
+#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
+#   define V8_HAVE_CXX11_OVERRIDE
+#   define V8_HAVE_CXX11_FINAL
+#  endif
+# else
+// '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655.
+#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
+#   define V8_HAVE_GXX_FINAL
+#  endif
+# endif
+
+#elif defined(_MSC_VER)
+
+# if _MSC_VER >= 1400
+#  define V8_HAVE_CXX11_OVERRIDE
+// MSVC currently spells "final" as "sealed".
+#  define V8_HAVE_MSVC_SEALED
+# endif
+
+#endif


 #if __cplusplus >= 201103L
@@ -375,6 +419,33 @@
 #endif


+// Annotate a virtual method indicating it must be overriding a virtual
+// method in the parent class.
+// Use like:
+//   virtual void bar() V8_OVERRIDE;
+#if defined(V8_HAVE_CXX11_OVERRIDE)
+#define V8_OVERRIDE override
+#else
+#define V8_OVERRIDE
+#endif
+
+
+// Annotate a virtual method indicating that subclasses must not override it,
+// or annotate a class to indicate that it cannot be subclassed.
+// Use like:
+//   class B V8_FINAL : public A {};
+//   virtual void bar() V8_FINAL;
+#if defined(V8_HAVE_CXX11_FINAL)
+#define V8_FINAL final
+#elif defined(V8_HAVE_GXX_FINAL)
+#define V8_FINAL __final
+#elif defined(V8_HAVE_MSVC_SEALED)
+#define V8_FINAL sealed
+#else
+#define V8_FINAL
+#endif
+
+
 #if defined(__GNUC__) && __GNUC__ >= 4
 #define MUST_USE_RESULT __attribute__ ((warn_unused_result))
 #else

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to