From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 65561 invoked by alias); 14 Dec 2018 20:42:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 65551 invoked by uid 89); 14 Dec 2018 20:42:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=revealed, issuing, trivial_fn_p X-HELO: mail-qt1-f180.google.com Received: from mail-qt1-f180.google.com (HELO mail-qt1-f180.google.com) (209.85.160.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Dec 2018 20:42:25 +0000 Received: by mail-qt1-f180.google.com with SMTP id e5so7654072qtr.12 for ; Fri, 14 Dec 2018 12:42:25 -0800 (PST) Return-Path: Received: from [192.168.1.132] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id f19sm3969350qtf.1.2018.12.14.12.42.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 12:42:23 -0800 (PST) Subject: Re: [C++ Patch] [PR c++/88146] do not crash synthesizing inherited ctor(...) To: Alexandre Oliva , gcc-patches@gcc.gnu.org References: From: Jason Merrill Message-ID: <81ac6c22-8907-a166-b8df-80e06d2850da@redhat.com> Date: Fri, 14 Dec 2018 20:42:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-12/txt/msg01092.txt.bz2 On 12/6/18 7:23 PM, Alexandre Oliva wrote: > This patch started out from the testcase in PR88146, that attempted to > synthesize an inherited ctor without any args before a varargs > ellipsis and crashed while at that, because of the unguarded > dereferencing of the parm type list, that usually contains a > terminator. The terminator is not there for varargs functions, > however, and without any other args, we ended up dereferencing a NULL > pointer. Oops. > > Guarding the accesses there was easy, but I missed the sorry message > we got in other testcases that passed arguments through the ellipsis > in inherited ctors. I put a check in, and noticed the inherited ctors > were synthesized with the location assigned to the class name, > although they were initially assigned the location of the using > declaration. I decided the latter was better, and arranged for the > better location to be retained. > > Further investigation revealed the lack of a sorry message had to do > with the call being in a non-evaluated context, in this case, a > noexcept expression. The sorry would be correctly reported in other > contexts, so I rolled back the check I'd added, but retained the > source location improvement. > > I was still concerned about issuing sorry messages while instantiating > template ctors even in non-evaluated contexts, e.g., if a template > ctor had a base initializer that used an inherited ctor with enough > arguments that they'd go through an ellipsis. I wanted to defer the > instantiation of such template ctors, but that would have been wrong > for constexpr template ctors, and already done for non-constexpr ones. > So, I just consolidated multiple test variants into a single testcase > that explores and explains various of the possibilities I thought of. > > Regstrapped on x86_64- and i686-linux-gnu, mistakenly along with a patch > with a known regression, and got only that known regression. Retesting > without it. Ok to install? > > > for gcc/cp/ChangeLog > > PR c++/88146 > * method.c (do_build_copy_constructor): Do not crash with > ellipsis-only parm list. > (synthesize_method): Retain location of inherited ctor. > > for gcc/testsuite/ChangeLog > > PR c++/88146 > * g++.dg/cpp0x/inh-ctor32.C: New. > --- > gcc/cp/method.c | 9 + > gcc/testsuite/g++.dg/cpp0x/inh-ctor32.C | 229 +++++++++++++++++++++++++++++++ > 2 files changed, 234 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/inh-ctor32.C > > diff --git a/gcc/cp/method.c b/gcc/cp/method.c > index fd023e200538..41d609fb1de6 100644 > --- a/gcc/cp/method.c > +++ b/gcc/cp/method.c > @@ -643,7 +643,7 @@ do_build_copy_constructor (tree fndecl) > bool trivial = trivial_fn_p (fndecl); > tree inh = DECL_INHERITED_CTOR (fndecl); > > - if (!inh) > + if (parm && !inh) > parm = convert_from_reference (parm); If inh is false, we're a copy constructor, which always has a parm, so this hunk seems unnecessary. > > if (trivial) > @@ -677,7 +677,7 @@ do_build_copy_constructor (tree fndecl) > { > tree fields = TYPE_FIELDS (current_class_type); > tree member_init_list = NULL_TREE; > - int cvquals = cp_type_quals (TREE_TYPE (parm)); > + int cvquals = parm ? cp_type_quals (TREE_TYPE (parm)) : 0; This could also check !inh. Jason