From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21725 invoked by alias); 6 May 2016 16:15:48 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 21681 invoked by uid 89); 6 May 2016 16:15:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.1 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=FINAL, subsequently, HTo:U*jit, claims X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com From: David Malcolm To: gcc-patches@gcc.gnu.org, jit@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 1/2] Add OVERRIDE and FINAL macros to coretypes.h Date: Fri, 01 Jan 2016 00:00:00 -0000 Message-Id: <1462552846-17096-1-git-send-email-dmalcolm@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 06 May 2016 16:15:44 +0000 (UTC) X-SW-Source: 2016-q2/txt/msg00000.txt.bz2 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®rtested 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