Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Unified Diff: src/globals.h

Issue 23098004: Add FINAL and OVERRIDE macros for C++11 final/override. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Autoconfied for Sven :-) Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/globals.h
diff --git a/src/globals.h b/src/globals.h
index 26fd53114c62d582501e5d37c2c7791cb60cd99b..415b32b87a7b841efb09f4af6d7d6b8edfadc884 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -330,6 +330,50 @@ F FUNCTION_CAST(Address 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
#define DISALLOW_BY_DELETE = delete
#else
@@ -375,6 +419,33 @@ F FUNCTION_CAST(Address addr) {
#endif
+// Annotate a virtual method indicating it must be overriding a virtual
+// method in the parent class.
+// Use like:
+// virtual void bar() OVERRIDE;
+#if defined(V8_HAVE_CXX11_OVERRIDE)
+#define OVERRIDE override
+#else
+#define 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 FINAL : public A {};
+// virtual void bar() FINAL;
+#if defined(V8_HAVE_CXX11_FINAL)
+#define FINAL final
+#elif defined(V8_HAVE_GXX_FINAL)
+#define FINAL __final
+#elif defined(V8_HAVE_MSVC_SEALED)
+#define FINAL sealed
+#else
+#define FINAL
+#endif
+
+
#if defined(__GNUC__) && __GNUC__ >= 4
#define MUST_USE_RESULT __attribute__ ((warn_unused_result))
#else
« no previous file with comments | « src/ast.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698