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 C0D29383F84B for ; Tue, 27 Oct 2020 17:39:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C0D29383F84B Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-jBt-ybCONoecTRiCoaS0yA-1; Tue, 27 Oct 2020 13:38:58 -0400 X-MC-Unique: jBt-ybCONoecTRiCoaS0yA-1 Received: by mail-qt1-f197.google.com with SMTP id n7so1222669qta.7 for ; Tue, 27 Oct 2020 10:38:58 -0700 (PDT) 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 :content-transfer-encoding; bh=+iYoLs530qVbZbnzhOc2K9fM9OxtBrBipZ+xZ4f5M4Q=; b=QJdGtBjILgrqNNobCWOkcyESJdL/rXk6D03nSxNdVINS8g+Redwh35Q0cUW/eXKLR6 FE6Xr1bBtAC6eX5S5BmyXu+pw5WCc3m8dM4YFA37dElK/7KBPLa5ah/u2LBesxNRTL5O zEF1pn99faFqXxco1B27l4vDjVOEg1PjQhPoGyRRnaigeUsWQOJZDEFyfQY6ADweyX5q BnRth5xLJOuN2W/ux/D4vIGyIUH1zaccZnNB14S5LZgddVcaiNoWSY23R8Kc0KWVS4qd Yr+JIyE3cGmSiSkL+jg1WJpNxfrgjG605dppExHU8e0YFxwznSm4FVyyy7UBkjPi8XNc YSag== X-Gm-Message-State: AOAM532Ei5ZNqNU1rB2QZOTSeSe2kGlLa2Ws26KZuL59dVx24Ww3mliu uMzJnkZzAg3Lk6psZIGIa3PpCaVcsG2XSN34jWgMfxUCyLMFV8UNmsvFOrHF6fTDguew9KxPG5p 1ZZEKuJvBX/9t2tAWqg== X-Received: by 2002:a37:7183:: with SMTP id m125mr3250995qkc.237.1603820338070; Tue, 27 Oct 2020 10:38:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJr1Moz3dJ46jH/OE0CQPy4dyGfOt9vsBKzaTxLncvloP2WYJxLYIehib8kwtYv/0zS3oHTg== X-Received: by 2002:a37:7183:: with SMTP id m125mr3250964qkc.237.1603820337719; Tue, 27 Oct 2020 10:38:57 -0700 (PDT) Received: from [192.168.1.148] (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 184sm1152071qkl.34.2020.10.27.10.38.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Oct 2020 10:38:56 -0700 (PDT) Subject: Re: [PATCH] c++: Implement DR2303 [PR97453] To: kamlesh kumar Cc: gcc-patches List , Marek Polacek References: From: Jason Merrill Message-ID: <83f496cc-58ee-419a-d2ae-02005a2ab398@redhat.com> Date: Tue, 27 Oct 2020 13:38:56 -0400 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.003 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Status: No, score=-17.2 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: Tue, 27 Oct 2020 17:39:03 -0000 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? > > > > > ------------------------------------------------------- > > > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c > > > index dc664ec3798..7adf461e108 100644 > > > --- a/gcc/cp/pt.c > > > +++ b/gcc/cp/pt.c > > > @@ -22643,8 +22643,9 @@ static enum template_base_result > > >   get_template_base (tree tparms, tree targs, tree parm, tree arg, > > >       bool explain_p, tree *result) > > >   { > > > -  tree rval = NULL_TREE; > > > +  *result = NULL_TREE; > > >     tree binfo; > > > +  hash_set binfo_set; > > > > > >     gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (arg))); > > > > > > @@ -22659,31 +22660,51 @@ get_template_base (tree tparms, tree targs, > > > tree parm, tree arg, > > >     /* Walk in inheritance graph order.  The search order is not > > >        important, and this avoids multiple walks of virtual bases.  */ > > >     for (binfo = TREE_CHAIN (binfo); binfo; binfo = TREE_CHAIN (binfo)) > > > -    { > > > -      tree r = try_class_unification (tparms, targs, parm, > > > -       BINFO_TYPE (binfo), explain_p); > > > - > > > -      if (r) > > > - { > > > -   /* If there is more than one satisfactory baseclass, then: > > > - > > > -        [temp.deduct.call] > > > +     { > > > +       tree r = try_class_unification (tparms, targs, parm, > > > +                       BINFO_TYPE (binfo), explain_p); > > > +       if (r) > > > +         { > > > +           binfo_set.add(r); > > > +         } > > > +     } > > > > > > -       If they yield more than one possible deduced A, the type > > > -       deduction fails. > > > +  /* If there is more than one satisfactory baseclass, then: > > > +     [temp.deduct.call] > > > +          If they yield more than one possible deduced A, the type > > > +          deduction fails. > > > +     However, 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.  */ > > > +  for (hash_set::iterator it = binfo_set.begin(); > > > +                                it != binfo_set.end(); ++it) > > > +    { > > > +      binfo = TYPE_BINFO (*it); > > > +      for (binfo = TREE_CHAIN (binfo); binfo; binfo = TREE_CHAIN > (binfo)) > > > +        { > > > +          tree r = try_class_unification (tparms, targs, parm, > > > +                          BINFO_TYPE (binfo), explain_p); > > > +          if (r && binfo_set.contains(r)) > > > +            { > > > +              binfo_set.remove(r); > > > +            } > > > +        } > > > +    } > > > > > > -      applies.  */ > > > -   if (rval && !same_type_p (r, rval)) > > > -     { > > > -       *result = NULL_TREE; > > > -       return tbr_ambiguous_baseclass; > > > -     } > > > +  if (binfo_set.elements() > 1) > > > +    { > > > +      return tbr_ambiguous_baseclass; > > > +    } > > > > > > -   rval = r; > > > - } > > > +  if (binfo_set.is_empty()) > > > +    { > > > +      return tbr_success; > > >       } > > > > > > -  *result = rval; > > > +  if (binfo_set.elements() == 1) > > > +    { > > > +      *result = *binfo_set.begin(); > > > +    } > > >     return tbr_success; > > >   } > > > > > > diff --git a/gcc/testsuite/g++.dg/DRs/dr2303.C > > > b/gcc/testsuite/g++.dg/DRs/dr2303.C > > > new file mode 100644 > > > index 00000000000..b4c23332358 > > > --- /dev/null > > > +++ b/gcc/testsuite/g++.dg/DRs/dr2303.C > > > @@ -0,0 +1,20 @@ > > > +// DR 2303 > > > +// PR c++/97453 > > > +// { dg-do compile { target c++11 } } > > > + > > > +template > > > +struct A; > > > +template <> > > > +struct A<> {}; > > > +template > > > +struct A : A {}; > > > +struct B : A {}; > > > + > > > +template > > > +void f(const A &) { > > > +  static_assert(sizeof...(T) == 2, "it should duduce to A"); > > > +} > > > + > > > +void g() { > > > +  f(B{}); > > > +} > > > -------------------------------- > > > > > > ./kamlesh > > > > >