From patchwork Thu Jul 21 15:23:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 106084 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2A09FB6F71 for ; Fri, 22 Jul 2011 01:23:34 +1000 (EST) Received: (qmail 5881 invoked by alias); 21 Jul 2011 15:23:33 -0000 Received: (qmail 5873 invoked by uid 22791); 21 Jul 2011 15:23:32 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-fx0-f49.google.com (HELO mail-fx0-f49.google.com) (209.85.161.49) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 Jul 2011 15:23:18 +0000 Received: by fxd20 with SMTP id 20so2806622fxd.22 for ; Thu, 21 Jul 2011 08:23:17 -0700 (PDT) Received: by 10.223.1.12 with SMTP id 12mr434319fad.113.1311261796841; Thu, 21 Jul 2011 08:23:16 -0700 (PDT) Received: from ville-laptop.gmail.com (dsl-olubrasgw1-ff2fc100-74.dhcp.inet.fi [88.193.47.74]) by mx.google.com with ESMTPS id w11sm1454558faj.38.2011.07.21.08.23.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 21 Jul 2011 08:23:15 -0700 (PDT) Date: Thu, 21 Jul 2011 18:23:06 +0300 Message-ID: <87d3h33bfp.wl%ville@ville-laptop> From: Ville Voutilainen To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com Subject: [PATCH] C++0x, warnings for uses of override/final in non-c++0x mode, add __final for non-c++0x mode User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.7 Emacs/23.1 (i486-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Tested on Linux/X86-32. 2011-07-21 Ville Voutilainen Warn about the use of final/override in non-c++0x mode, and add __final for non-c++0x mode. * cp-tree.h (cpp0x_warn_str): Add CPP0X_OVERRIDE_CONTROLS. * error.c (maybe_warn_cpp0x): Adjust. * parser.c (cp_parser_virt_specifier_seq_opt): Use it. Add '__final' as a non-c++0x alternative for 'final'. * override1.C: This test should use c++0x mode. * override3.C: New. Test the diagnostics in c++98 mode. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index c590585..fb17178 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -393,7 +393,9 @@ typedef enum cpp0x_warn_str /* defaulted and deleted functions */ CPP0X_DEFAULTED_DELETED, /* inline namespaces */ - CPP0X_INLINE_NAMESPACES + CPP0X_INLINE_NAMESPACES, + /* override controls, override/final */ + CPP0X_OVERRIDE_CONTROLS } cpp0x_warn_str; /* The various kinds of operation used by composite_pointer_type. */ diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 2d7c0f1..d435bbe 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -3227,6 +3227,11 @@ maybe_warn_cpp0x (cpp0x_warn_str str) "inline namespaces " "only available with -std=c++0x or -std=gnu++0x"); break; + case CPP0X_OVERRIDE_CONTROLS: + pedwarn (input_location, 0, + "override controls (override/final) " + "only available with -std=c++0x or -std=gnu++0x"); + break; default: gcc_unreachable(); } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2851801..dc54dc2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -15596,9 +15596,19 @@ cp_parser_virt_specifier_seq_opt (cp_parser* parser) if (token->type != CPP_NAME) break; if (!strcmp (IDENTIFIER_POINTER(token->u.value), "override")) - virt_specifier = VIRT_SPEC_OVERRIDE; + { + maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS); + virt_specifier = VIRT_SPEC_OVERRIDE; + } else if (!strcmp (IDENTIFIER_POINTER(token->u.value), "final")) - virt_specifier = VIRT_SPEC_FINAL; + { + maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS); + virt_specifier = VIRT_SPEC_FINAL; + } + else if (!strcmp (IDENTIFIER_POINTER(token->u.value), "__final")) + { + virt_specifier = VIRT_SPEC_FINAL; + } else break; diff --git a/gcc/testsuite/g++.dg/cpp0x/override1.C b/gcc/testsuite/g++.dg/cpp0x/override1.C index 83e0479..ba580b5 100644 --- a/gcc/testsuite/g++.dg/cpp0x/override1.C +++ b/gcc/testsuite/g++.dg/cpp0x/override1.C @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-options "--std=c++0x" } struct B { virtual void f() final {} diff --git a/gcc/testsuite/g++.dg/cpp0x/override3.C b/gcc/testsuite/g++.dg/cpp0x/override3.C new file mode 100644 index 0000000..f3942e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/override3.C @@ -0,0 +1,24 @@ +// { dg-do compile } +// { dg-options "--std=c++98" } + +struct B final {}; // { dg-warning "only available with -std=c++0x or -std=gnu++0x" } + +struct D : B {}; // { dg-error "cannot derive from ‘final’ base" } + +struct E __final {}; + +struct F : E {}; { dg-error "cannot derive from ‘final’ base" } + +struct G +{ + virtual void f(); +}; + +struct H : G +{ + void f() override; // { dg-warning "only available with -std=c++0x or -std=gnu++0x" } +}; + +int main() +{ +}