From patchwork Tue May 10 07:03:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 94956 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 903C7B6EEE for ; Tue, 10 May 2011 17:03:53 +1000 (EST) Received: (qmail 31219 invoked by alias); 10 May 2011 07:03:50 -0000 Received: (qmail 31199 invoked by uid 22791); 10 May 2011 07:03:48 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST, TW_FN, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-ey0-f175.google.com (HELO mail-ey0-f175.google.com) (209.85.215.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 May 2011 07:03:33 +0000 Received: by eye27 with SMTP id 27so1941706eye.20 for ; Tue, 10 May 2011 00:03:31 -0700 (PDT) Received: by 10.213.10.2 with SMTP id n2mr2776636ebn.112.1305011011546; Tue, 10 May 2011 00:03:31 -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 y44sm4068035eey.12.2011.05.10.00.03.30 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 May 2011 00:03:31 -0700 (PDT) Date: Tue, 10 May 2011 10:03:22 +0300 Message-ID: <87sjsnxcjp.wl%ville@ville-laptop> From: Ville Voutilainen To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: Re: [PATCH] C++0x, fixes for override/final In-Reply-To: <20110510064602.GZ17079@tyan-ft48-01.lab.bos.redhat.com> References: <87wrhzzggw.wl%ville@ville-laptop> <4DC8C33E.40400@redhat.com> <87r587hxkx.wl%ville@ville-laptop> <20110510064602.GZ17079@tyan-ft48-01.lab.bos.redhat.com> 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 At Tue, 10 May 2011 08:46:02 +0200, Jakub Jelinek wrote: > Hi! > Just small style nits: > s/int/bool/;s/0/false/;s/1/true/ > And the above condition is short enough that it could be on one line. Ok. Tests still pass. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 12db2bc..94a339d 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2453,6 +2453,7 @@ get_basefndecls (tree name, tree t) void check_for_override (tree decl, tree ctype) { + bool overrides_found = false; if (TREE_CODE (decl) == TEMPLATE_DECL) /* In [temp.mem] we have: @@ -2467,7 +2468,10 @@ check_for_override (tree decl, tree ctype) /* Set DECL_VINDEX to a value that is neither an INTEGER_CST nor the error_mark_node so that we know it is an overriding function. */ - DECL_VINDEX (decl) = decl; + { + DECL_VINDEX (decl) = decl; + overrides_found = true; + } if (DECL_VIRTUAL_P (decl)) { @@ -2477,11 +2481,10 @@ check_for_override (tree decl, tree ctype) if (DECL_DESTRUCTOR_P (decl)) TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true; } - else if (DECL_OVERRIDE_P (decl)) - { - DECL_VINDEX (decl) = error_mark_node; - error ("%q+#D marked override, but does not override", decl); - } + else if (DECL_FINAL_P (decl)) + error ("%q+#D marked final, but is not virtual", decl); + if (DECL_OVERRIDE_P (decl) && !overrides_found) + error ("%q+#D marked override, but does not override", decl); } /* Warn about hidden virtual functions that are not overridden in t. diff --git a/gcc/testsuite/g++.dg/inherit/virtual9.C b/gcc/testsuite/g++.dg/inherit/virtual9.C index d3175e1..83e0479 100644 --- a/gcc/testsuite/g++.dg/inherit/virtual9.C +++ b/gcc/testsuite/g++.dg/inherit/virtual9.C @@ -3,6 +3,7 @@ struct B { virtual void f() final {} virtual void g() {} + virtual void x() const {} }; struct B2 @@ -20,7 +21,12 @@ template struct D2 : T void h() override {} // { dg-error "marked override, but does not override" } }; -struct D3 : D +template struct D3 : T +{ + void h() override {} +}; + +struct D4 : D { void g() {} // { dg-error "virtual function" } }; @@ -30,10 +36,25 @@ struct B3 virtual void f() final final {} // { dg-error "duplicate virt-specifier" } }; -void g() override {} // { dg-error "virt-specifiers" } +struct B4 +{ + void f() final {} // { dg-error "marked final, but is not virtual" } +}; + +struct D5 : B +{ + void ff() override {} // { dg-error "marked override, but does not override" } + virtual void fff() override {} // { dg-error "marked override, but does not override" } + virtual void x() override {} // { dg-error "marked override, but does not override" } + void g() override; +}; + +void D5::g() override {} // { dg-error "not allowed outside a class definition" } +void g() override {} // { dg-error "not allowed outside a class definition" } int main() { - D2 d2; - D2 d3; + D2 d; + D2 d2; + D3 d3; }