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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C93573838214 for ; Tue, 31 May 2022 19:04:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C93573838214 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-P3ph3yp2McePwduoGyd9Bw-1; Tue, 31 May 2022 15:04:14 -0400 X-MC-Unique: P3ph3yp2McePwduoGyd9Bw-1 Received: by mail-qt1-f200.google.com with SMTP id c4-20020ac85a84000000b002f923018222so12922321qtc.16 for ; Tue, 31 May 2022 12:04:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=jNngphL/cmycCMNzsBMx6dtX3AZM37t2h6/AvzifldE=; b=D7kI4n5vUVcD0oZRjUlPYiKzjaVfRoX31uFJeN+b2AnX2IV22ImrOBAkysFSUDCxCH kHaSeJmI7P/tLQcH59nLeCvGSfWZUjM1UcLu0o70yEJZ4oL+bmlsMv/RRrDb088icHT9 rLBY4ciRVOMxZERkY+8maqyUSQVZXquBMnFEjMODw1/RPYwX3I4TnErEhaz50Qgy6TSQ 5fv4WSLjkULoum6Q3Qgr1Ltor6/KtgWvVZVjU0BYPAwt2nNNc1aDm/HEZ5p9cKpuyonM CAJXks4HwluwaEP7De1K7ORZ94jwaPTcSP/6Vcm38qp/QM1+OeUNHwUUIIotTPbL1zkf NIQA== X-Gm-Message-State: AOAM530EQU27OnFJE+RRlHRXEfqkxoze1DLuFYK/I6Od1NDXc/5L/W0X guXWqSj782ybc8aSxa5ilrRGVxT6tY8H+1kXSqSunO9slUVAsrvOH4HbTfSlwppJSmkRbAYKpbr /8J6vc2woGQ5240SLHQ== X-Received: by 2002:a05:622a:1193:b0:304:b6d3:3629 with SMTP id m19-20020a05622a119300b00304b6d33629mr6368391qtk.202.1654023853300; Tue, 31 May 2022 12:04:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTl+9ug0xS19+tgUCFERtJQT2ZAzNxnOybZnFveFEdgr/b0VuWptl0yjbsoeWj6NwTJ9bxqg== X-Received: by 2002:a05:622a:1193:b0:304:b6d3:3629 with SMTP id m19-20020a05622a119300b00304b6d33629mr6368364qtk.202.1654023852947; Tue, 31 May 2022 12:04:12 -0700 (PDT) Received: from [192.168.1.100] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id h189-20020a3753c6000000b006a61650043bsm5222029qkb.124.2022.05.31.12.04.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 May 2022 12:04:11 -0700 (PDT) Message-ID: <641bd76b-4a6e-f975-6abe-3182b85a7ec3@redhat.com> Date: Tue, 31 May 2022 15:04:10 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] c++: non-dep call with empty TYPE_BINFO [PR105758] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20220531162803.3730586-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20220531162803.3730586-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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, 31 May 2022 19:04:17 -0000 On 5/31/22 12:28, Patrick Palka wrote: > Here the out-of-line definition of Z::z causes duplicate_decls to > change z's type to use the implicit instantiation Z rather than the > corresponding primary template type (which is also the type of the > injected class name), and the former, being a dependent specialization, > lacks a TYPE_BINFO (although its TYPE_CANONICAL was set by a special > case in lookup_template_class_1 to point to the latter). > > Later, when processing the non-dependent call z->foo(0), build_over_call > relies on the object argument's TYPE_BINFO to build the templated form > for this call, which fails because the object argument type has empty > TYPE_BINFO due to the above. > > It seems weird that the implicit instantiation Z doesn't have the > same TYPE_BINFO as the primary template type Z, despite them being > proclaimed equivalent via TYPE_CANONICAL. So I tried also setting > TYPE_BINFO in the special case in lookup_template_class_1, but that led > to some problems with constrained partial specializations of the form > Z. I'm not sure what, if anything, we ought to do about the subtle > differences between these two kinds of the same type. > > Fortunately it seems we don't need to rely on TYPE_BINFO at all in > build_over_call here -- the z_candidate struct already contains the > exact binfos we need to rebuild the BASELINK for the templated form. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk/12? OK. > PR c++/105758 > > gcc/cp/ChangeLog: > > * call.cc (build_over_call): Use z_candidate::conversion_path > and ::access_path instead of TYPE_BINFO to build the BASELINK > for the templated form. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/non-dependent24.C: New test. > --- > gcc/cp/call.cc | 4 ++-- > .../g++.dg/template/non-dependent24.C | 19 +++++++++++++++++++ > 2 files changed, 21 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/template/non-dependent24.C > > diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc > index 14c6037729f..85fe9b5ab85 100644 > --- a/gcc/cp/call.cc > +++ b/gcc/cp/call.cc > @@ -9244,8 +9244,8 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) > } > else > { > - tree binfo = TYPE_BINFO (TREE_TYPE (first_arg)); > - callee = build_baselink (binfo, binfo, fn, NULL_TREE); > + callee = build_baselink (cand->conversion_path, cand->access_path, > + fn, NULL_TREE); > callee = build_min (COMPONENT_REF, TREE_TYPE (fn), > first_arg, callee, NULL_TREE); > } > diff --git a/gcc/testsuite/g++.dg/template/non-dependent24.C b/gcc/testsuite/g++.dg/template/non-dependent24.C > new file mode 100644 > index 00000000000..0ddc75c78ee > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/non-dependent24.C > @@ -0,0 +1,19 @@ > +// PR c++/105758 > + > +struct A { > + void foo(int); > +}; > + > +template > +struct Z : A { > + static Z *z; > + void bar(); > +}; > + > +template > +Z *Z::z; > + > +template > +void Z::bar() { > + z->foo(0); > +}