From patchwork Tue Feb 14 08:39:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 141070 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 A50721007E8 for ; Tue, 14 Feb 2012 19:40:10 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1329813611; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=WLETHGw JXacZd7pVA6RjfAIdpOY=; b=Jjpm8M3QjGndz9YnuDo+46BWaYlPYh+9QPhKL/2 XRtqtKpjb11BCPnA6yPBtQ0l46kXrIP+pYfSkwUk28NHf/KZJVKev1XKNCaQPh5r K8xiXw5HXkR36VFoLMkHi/97NMNWJcZ8oJ4csH1L7xQiT+92tuDo4Z2nLFjpLXQv lxyk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=CNYhuB492wR8VU0b7j1mzB76/SwxGPCwvHwJKqR2AW/+ok/7YwEp+sbTKz1BZi pkTBP5rr61K1GHTL65TXnB+pgzdmkzPUKbMQaeweCMoa13pWKJNkmdlI3oSntLh3 6RWfnE7nG+ThSzdoofHGF7USYrYnEyluGwZ9aOCcdp/HI=; Received: (qmail 7065 invoked by alias); 14 Feb 2012 08:40:05 -0000 Received: (qmail 7055 invoked by uid 22791); 14 Feb 2012 08:40:03 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Feb 2012 08:39:43 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1E8dh8U016546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 14 Feb 2012 03:39:43 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q1E8dgQl024998 for ; Tue, 14 Feb 2012 03:39:43 -0500 Received: from [0.0.0.0] (ovpn-113-143.phx2.redhat.com [10.3.113.143]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id q1E8dfUs027648 for ; Tue, 14 Feb 2012 03:39:42 -0500 Message-ID: <4F3A1DCD.7070405@redhat.com> Date: Tue, 14 Feb 2012 00:39:41 -0800 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.1) Gecko/20120209 Thunderbird/10.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/39055 (accepts-valid with 'this' in default argument) 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 This is a regression since 3.3; discussion at the C++ meeting last week concluded both that yes, this is ill-formed, and we think it should be ill-formed. Tested x86_64-pc-linux-gnu, applying to trunk. commit 399365c251914176b5b34076e5a7b4658c06e917 Author: Jason Merrill Date: Fri Feb 10 22:57:05 2012 -1000 PR c++/39055 * decl.c (local_variable_p_walkfn): Don't check DECL_ARTIFICIAL. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8fcfbd5..f0ba181 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10509,7 +10509,9 @@ static tree local_variable_p_walkfn (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) { - if (local_variable_p (*tp) && !DECL_ARTIFICIAL (*tp)) + /* Check DECL_NAME to avoid including temporaries. We don't check + DECL_ARTIFICIAL because we do want to complain about 'this'. */ + if (local_variable_p (*tp) && DECL_NAME (*tp)) return *tp; else if (TYPE_P (*tp)) *walk_subtrees = 0; @@ -10517,7 +10519,6 @@ local_variable_p_walkfn (tree *tp, int *walk_subtrees, return NULL_TREE; } - /* Check that ARG, which is a default-argument expression for a parameter DECL, is valid. Returns ARG, or ERROR_MARK_NODE, if something goes wrong. DECL may also be a _TYPE node, rather than a @@ -10578,7 +10579,10 @@ check_default_argument (tree decl, tree arg) var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL); if (var) { - error ("default argument %qE uses local variable %qD", arg, var); + if (DECL_NAME (var) == this_identifier) + permerror (input_location, "default argument %qE uses %qD", arg, var); + else + error ("default argument %qE uses local variable %qD", arg, var); return error_mark_node; } diff --git a/gcc/testsuite/g++.dg/overload/defarg5.C b/gcc/testsuite/g++.dg/overload/defarg5.C new file mode 100644 index 0000000..06ea6bf --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/defarg5.C @@ -0,0 +1,7 @@ +// PR c++/39055 + +struct A +{ + int i; + A() { void foo(int=i); } // { dg-error "this" } +};