From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id DCFE33850432 for ; Mon, 2 Nov 2020 16:18:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DCFE33850432 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-586-HFsj2twsNOKavrGmwUESZg-1; Mon, 02 Nov 2020 11:18:06 -0500 X-MC-Unique: HFsj2twsNOKavrGmwUESZg-1 Received: by mail-qt1-f199.google.com with SMTP id z12so8361404qto.4 for ; Mon, 02 Nov 2020 08:18:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=+0L4NkBNE2Mv2KS1DODkZsyTBDU4QU9Xx3v7OQPyVok=; b=Xj6msG8EBLir5ayFANhY79tCoVGH09aHi9p6aZ9/YUNSOXlaoQSwCiuhACtwdoI7PH b5HNxcrjZ9ZhqTZI3jKWWAJ/3wW3lDbG+uI3Qq+4dEWYo7uyzUrlpSOEa+ctxhVCi1kT 4QvFoVG7/cduIcvbbTRpUpFtGfzfxeQ7E2EgcRjolXK2ZCkcRf+HyzCjaU5LffGpGUPp OOUpiQpaFLJq7cpuvN15rYG51yr8nRiFZdIctyWaspjg8zMeqexEdjMLsTmlrQqy1IXj 9KGHcvzowGGodYWQ261lg/okPSH4RkxsCPF/AeeOaA2xN4VcSaV3+oT8/X8F4zlC3GAa 0n3Q== X-Gm-Message-State: AOAM532m+2jLR+5ViZj2WfOrok5aoJQFCM7GdPSurIbMdQeZGX90kL/V Qmh1Dj46EvI7gipxmc2LFxd6m1xAx4HL0n/xT3jo5LQlJLXFFFKtBnxRJ7K3jVAQTLkAbNQPBku K5SKyyBazOAZJFrXf6A== X-Received: by 2002:ac8:7110:: with SMTP id z16mr8994921qto.14.1604333885776; Mon, 02 Nov 2020 08:18:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2CqOD0uUBbTGGllIIINZ/PNM5HLA1b3BTQPk1Y0mejrkq+WFJ2zpR++DDV1F7gm5dwf0juw== X-Received: by 2002:ac8:7110:: with SMTP id z16mr8994888qto.14.1604333885408; Mon, 02 Nov 2020 08:18:05 -0800 (PST) Received: from [192.168.0.26] (209-6-118-145.s1935.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [209.6.118.145]) by smtp.gmail.com with ESMTPSA id 198sm8358815qki.117.2020.11.02.08.18.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Nov 2020 08:18:04 -0800 (PST) Subject: Re: [PATCH] c++: Implement DR2303 [PR97453] To: kamlesh kumar Cc: gcc-patches List , Marek Polacek References: <83f496cc-58ee-419a-d2ae-02005a2ab398@redhat.com> From: Jason Merrill Message-ID: <46e6b452-a3af-bab4-52e7-c700da8d5d54@redhat.com> Date: Mon, 2 Nov 2020 11:18:03 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="------------012A644EFC767C755DADBD0C" Content-Language: en-US X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Nov 2020 16:18:14 -0000 This is a multi-part message in MIME format. --------------012A644EFC767C755DADBD0C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 11/2/20 10:10 AM, kamlesh kumar wrote: > addressed jason comments. > no regression due to this, tested on x86_64 linux. > > On Tue, Oct 27, 2020 at 11:09 PM Jason Merrill wrote: >> >> On 10/22/20 1:31 PM, kamlesh kumar wrote: >>> Attaching the patch file. >>> >>> >>Instead of building a hash table, would it work to handle ambiguity by >>> >>checking whether one of the classes is a base of the other? >> >>> Fixing for cases like: struct B: A,A may not be cleaner >>> this way. >> >> Why not? Your patch does extra work even when there's no ambiguity. >> >>> On Thu, Oct 22, 2020 at 3:23 AM Jason Merrill >> > wrote: >>> > >>> > On 10/21/20 6:32 AM, kamlesh kumar wrote: >>> > > gcc/cp/ChangeLog >>> > > ----------------------------------- >>> > > >>> > > 2020-10-21 Kamlesh Kumar >> > >>> > > >>> > > PR c++/97453 >>> > > * pt.c (get_template_base): Implement DR2303, >>> > > Consider closest base while template >>> > > deduction when base of base also matches. >>> > > >>> > > gcc/testsuite/ChangeLog >>> > > ------------------------------------------ >>> > > >>> > > 2020-10-21 Kamlesh Kumar >> > >>> > > >>> > > * g++.dg/Drs/dr2303.C: New Test >>> > > >>> > > -------------------------------------------------- >>> > > >>> > > As part of this patch I Implemented fix for below defect report in cwg >>> > > https://wg21.cmeerw.net/cwg/issue2303 . >>> > >>> > Thanks! >>> > >>> > Please see https://gcc.gnu.org/contribute.html for guidance on email >>> > subject lines; for this patch I'd think something like >>> > >>> > [PATCH] c++: Implement DR2303 [PR97453] >>> > >>> > Also, your patch was corrupted by word wrap; the easiest way to avoid >>> > that is probably to attach the file rather than copy it into the message. >>> > >>> > > Reg tested on x86_64 and did not found any failure. >>> > > Patch summary: Remove base of base from list of bases >>> > > >>> > > created a hash_set from list of bases and then iterate over each >>> > > element of hash_set and find its list of bases and remove this from >>> > > hash_set if present. >>> > > and finally, deduction succeeds if in hash_set remains only single >>> > > element or it's empty. >>> > > otherwise deduction is ambiguous. >>> > >>> > Instead of building a hash table, would it work to handle ambiguity by >>> > checking whether one of the classes is a base of the other? This is what I had in mind; it seems clearer to me. Do you see a reason this wouldn't work? Also, I notice that you still don't seem to have a copyright assignment on file with the FSF. I and Jonathan Wakely both asked about it last year; has there been any progress on that? Your patch is too large to go in without a copyright assignment, so it's probably simplest to go ahead with mine. Thanks, Jason --------------012A644EFC767C755DADBD0C Content-Type: text/x-patch; charset=UTF-8; name="dr2303.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dr2303.diff" commit 6b0fc692d57f38ec69ea739117ac3d4552cd0d23 Author: kamlesh kumar Date: Mon Nov 2 20:40:21 2020 +0530 c++: Implement DR2303 [PR97453] gcc/cp/ChangeLog 2020-10-21 Kamlesh Kumar Jason Merrill PR c++/97453 DR2303 * pt.c (get_template_base): Implement DR2303, Consider closest base while template deduction when base of base also matches. gcc/testsuite/ChangeLog 2020-10-21 Kamlesh Kumar g++.dg/DRs/dr2303.C: New test. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f31a1a70473..245b7a83a92 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22693,8 +22693,20 @@ get_template_base (tree tparms, tree targs, tree parm, tree arg, applies. */ if (rval && !same_type_p (r, rval)) { - *result = NULL_TREE; - return tbr_ambiguous_baseclass; + /* [temp.deduct.call]/4.3: If there is a class C that is a + (direct or indirect) base class of D and derived (directly or + indirectly) from a class B and that would be a valid deduced + A, the deduced A cannot be B or pointer to B, respectively. */ + if (DERIVED_FROM_P (r, rval)) + /* Ignore r. */ + continue; + else if (DERIVED_FROM_P (rval, r)) + /* Discard rval. */; + else + { + *result = NULL_TREE; + return tbr_ambiguous_baseclass; + } } rval = r; diff --git a/gcc/testsuite/g++.dg/DRs/dr2303.C b/gcc/testsuite/g++.dg/DRs/dr2303.C new file mode 100644 index 00000000000..b6acb6e2197 --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr2303.C @@ -0,0 +1,37 @@ +// DR 2303 +// PR c++/97453 +// { dg-do compile { target c++11 } } + +template struct A; +template <> struct A<> +{ +}; +template struct A : A +{ +}; +struct B : A +{ +}; + +struct C : A, A // { dg-warning "direct base .A. inaccessible in .C. due to ambiguity" } +{ +}; + +struct D : A, A // { dg-warning "direct base .A. inaccessible in .D. due to ambiguity" } +{ +}; +template +void +f (const A &) +{ + static_assert (sizeof...(T) == 2, "it should duduce to A"); +} + + +void +g () +{ + f (B{}); + f (C{}); + f (D{}); +} --------------012A644EFC767C755DADBD0C--