public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Add OVERRIDE and FINAL macros to coretypes.h
@ 2016-01-01  0:00 David Malcolm
  2016-01-01  0:00 ` Pedro Alves
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: David Malcolm @ 2016-01-01  0:00 UTC (permalink / raw)
  To: gcc-patches, jit; +Cc: David Malcolm

C++11 adds the ability to add "override" after an implementation of a
virtual function in a subclass, to:
(A) document that this is an override of a virtual function
(B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
of the type signature).

Similarly, it allows us to add a "final" to indicate that no subclass
may subsequently override the vfunc.

We use virtual functions in a few places (e.g. in the jit), so it would
be good to get this extra checking.

This patch adds OVERRIDE and FINAL as macros to coretypes.h
allowing us to get this extra checking when compiling with a compiler
that implements C++11 or later (e.g. gcc 6 by default),
but without requiring C++11.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

Does "final" imply "override"?  Is "final override" a tautology?

gcc/ChangeLog:
	* coretypes.h (OVERRIDE): New macro.
	(FINAL): New macro.
---
 gcc/coretypes.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index 2932d73..b3a91a6 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -361,6 +361,31 @@ typedef void (*gt_pointer_operator) (void *, void *);
 typedef unsigned char uchar;
 #endif
 
+/* C++11 adds the ability to add "override" after an implementation of a
+   virtual function in a subclass, to:
+     (A) document that this is an override of a virtual function
+     (B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
+         of the type signature).
+
+   Similarly, it allows us to add a "final" to indicate that no subclass
+   may subsequently override the vfunc.
+
+   Provide OVERRIDE and FINAL as macros, allowing us to get these benefits
+   when compiling with C++11 support, but without requiring C++11.
+
+   For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards enables
+   this by default (actually GNU++14).  */
+
+#if __cplusplus >= 201103
+/* C++11 claims to be available: use it: */
+#define OVERRIDE override
+#define FINAL final
+#else
+/* No C++11 support; leave the macros empty: */
+#define OVERRIDE
+#define FINAL
+#endif
+
 /* Most host source files will require the following headers.  */
 #if !defined (GENERATOR_FILE) && !defined (USED_FOR_TARGET)
 #include "machmode.h"
-- 
1.8.5.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2017-02-04  0:55 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-01  0:00 [PATCH 1/2] Add OVERRIDE and FINAL macros to coretypes.h David Malcolm
2016-01-01  0:00 ` Pedro Alves
2016-01-01  0:00   ` Jason Merrill
2016-01-01  0:00   ` Pedro Alves
2016-01-01  0:00     ` Trevor Saunders
2016-01-01  0:00       ` Pedro Alves
2016-01-01  0:00       ` Move OVERRIDE/FINAL from gcc/coretypes.h to include/ansidecl.h (was: Re: [PATCH 1/2] Add OVERRIDE and FINAL macros to coretypes.h) Pedro Alves
2016-01-01  0:00         ` Move OVERRIDE/FINAL from gcc/coretypes.h to include/ansidecl.h Bernd Schmidt
2016-01-01  0:00           ` Pedro Alves
2016-01-01  0:00             ` Bernd Schmidt
2016-01-01  0:00               ` Pedro Alves
2016-01-01  0:00                 ` [wwwdocs, coding conventions] Mention OVERRIDE/FINAL David Malcolm
2016-01-01  0:00                   ` Pedro Alves
2017-01-01  0:00                   ` Gerald Pfeifer
2017-01-01  0:00                     ` Trevor Saunders
2017-01-01  0:00                   ` Gerald Pfeifer
2016-01-01  0:00 ` [PATCH 1/2] Add OVERRIDE and FINAL macros to coretypes.h Jakub Jelinek
2016-01-01  0:00   ` CONSTEXPR macro (was "Re: [PATCH 1/2] Add OVERRIDE and FINAL macros to coretypes.h") David Malcolm
2016-01-01  0:00     ` Jakub Jelinek
2016-01-01  0:00 ` [PATCH 2/2] jit: use FINAL and OVERRIDE throughout David Malcolm
2016-01-01  0:00   ` David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).