From patchwork Mon Mar 10 21:06:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 328832 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DA5962C2B81 for ; Tue, 11 Mar 2014 08:06:24 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=wtoxIokv4fj1rLUiV83wwaBhY1198KFm47RykNhR/6GdUG VpIpZ7OsvEZkVTmYSlOIE38Ta51f02QX/AsBcXRZ5MKxUUj/aI7EZvMPWRcEfnB5 bQvK1Poju0qUF9ZH9tZfiqLEx02LAV08Ob8eUuLAxs72Trm/qXAxiJUNNFB/0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=Htz3tUnIBZ4j9yBOVqyr/WDSx14=; b=Msv1/38K0YgUPZvPcSLZ RxLMk1Eof8+PdWwFGh8bVbVHS/MWwhNNeyj0QtL1DxJLF0pC7Sg2UFVmfIDeHx/a 2ms8/Daw0xvNDdjDZX1JRJFDLfkXNgAY7fVg5VfF2OMK79CQfE4QefcJ1U1a5QUy QN7x4G0d85U8YbLe4HeJTmQ= Received: (qmail 11056 invoked by alias); 10 Mar 2014 21:06:18 -0000 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 Received: (qmail 11043 invoked by uid 89); 10 Mar 2014 21:06:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Mar 2014 21:06:16 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2AL6EOX030641 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 10 Mar 2014 17:06:15 -0400 Received: from [10.10.116.21] ([10.10.116.21]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2AL6EQN017152 for ; Mon, 10 Mar 2014 17:06:14 -0400 Message-ID: <531E2946.80104@redhat.com> Date: Mon, 10 Mar 2014 17:06:14 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/60367 (wrong argument passing with {}) The problem was that we were failing to call convert_for_arg_passing when the default argument is a CONSTRUCTOR. I wasn't sure why I had added the CONSTRUCTOR special case in the first place, and looked back in git blame to see when it had come in...and found that it dated back to a Cygnus G++ merge back in the mists of time. So, not from the list-initialization work. Removing the special case fixes the bug; I'm sure that whatever it was originally intended to handle is now handled by the list-init stuff. Tested x86_64-pc-linux-gnu, applying to trunk. commit 31ecb3e7f77979f602b20e1358201326c0e4eedd Author: Jason Merrill Date: Mon Mar 10 15:51:42 2014 -0400 PR c++/60367 * call.c (convert_default_arg): Remove special handling for CONSTRUCTOR. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index b58c072..184e922 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6531,20 +6531,10 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum, /* We must make a copy of ARG, in case subsequent processing alters any part of it. */ arg = break_out_target_exprs (arg); - if (TREE_CODE (arg) == CONSTRUCTOR) - { - arg = digest_init (type, arg, complain); - arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT, - ICR_DEFAULT_ARGUMENT, fn, parmnum, - complain); - } - else - { - arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT, - ICR_DEFAULT_ARGUMENT, fn, parmnum, - complain); - arg = convert_for_arg_passing (type, arg, complain); - } + arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT, + ICR_DEFAULT_ARGUMENT, fn, parmnum, + complain); + arg = convert_for_arg_passing (type, arg, complain); pop_deferring_access_checks(); pop_defarg_context (); diff --git a/gcc/testsuite/g++.dg/overload/defarg8.C b/gcc/testsuite/g++.dg/overload/defarg8.C new file mode 100644 index 0000000..b3ddfbb --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/defarg8.C @@ -0,0 +1,22 @@ +// PR c++/60367 +// { dg-do run { target c++11 } } + +extern "C" int printf (const char *, ...); +extern "C" void abort(); + +void *p; +struct foo { + foo() { p = this; } + foo (const foo &) { abort(); } + ~foo() { if (p != this) abort(); } +}; + +void do_something( foo f = {} ) +{ + if (&f != p) abort(); +} + +int main() +{ + do_something(); +}