From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 26BCC389850D for ; Tue, 23 Jun 2020 02:09:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 26BCC389850D Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-321-g1p27PWXNb-VsBBsHCdUWg-1; Mon, 22 Jun 2020 22:09:36 -0400 X-MC-Unique: g1p27PWXNb-VsBBsHCdUWg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8087A8018D9 for ; Tue, 23 Jun 2020 02:09:35 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-116-110.rdu2.redhat.com [10.10.116.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ABCF71688; Tue, 23 Jun 2020 02:09:35 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: Make convert_like complain about bad ck_ref_bind again [PR95789] Date: Mon, 22 Jun 2020 22:09:27 -0400 Message-Id: <20200623020927.172479-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-16.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, 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, 23 Jun 2020 02:09:39 -0000 convert_like issues errors about bad_p conversions at the beginning of the function, but in the ck_ref_bind case, it only issues them after we've called convert_like on the next conversion. This doesn't work as expected since r10-7096 because when we see a conversion from/to class type in a template, we return early, thereby missing the error, and a bad_p conversion goes by undetected. That made the attached test to compile even though it should not. I had thought that I could just move the ck_ref_bind/bad_p errors above to the rest of them, but that regressed diagnostics because expr then wasn't converted yet by the nested convert_like_real call. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk and 10? gcc/cp/ChangeLog: PR c++/95789 * call.c (convert_like_real): Do the normal processing for ck_ref_bind conversion that are bad_p. gcc/testsuite/ChangeLog: PR c++/95789 * g++.dg/conversion/ref4.C: New test. --- gcc/cp/call.c | 9 ++++++++- gcc/testsuite/g++.dg/conversion/ref4.C | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/conversion/ref4.C diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 2b39a3700fc..7b16895d5db 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7402,7 +7402,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, function. */ if (processing_template_decl && convs->kind != ck_identity - && (CLASS_TYPE_P (totype) || CLASS_TYPE_P (TREE_TYPE (expr)))) + && (CLASS_TYPE_P (totype) || CLASS_TYPE_P (TREE_TYPE (expr))) + /* Do the normal processing to give the bad_p errors in ck_ref_bind + to avoid losing the fact that this conversion was bad. Since we + are going to return error_mark_node, we don't care about trees + breaking in templates. */ + && !(convs->kind == ck_ref_bind + && convs->bad_p + && !next_conversion (convs)->bad_p)) { expr = build1 (IMPLICIT_CONV_EXPR, totype, expr); return convs->kind == ck_ref_bind ? expr : convert_from_reference (expr); diff --git a/gcc/testsuite/g++.dg/conversion/ref4.C b/gcc/testsuite/g++.dg/conversion/ref4.C new file mode 100644 index 00000000000..464a4cf6c0f --- /dev/null +++ b/gcc/testsuite/g++.dg/conversion/ref4.C @@ -0,0 +1,22 @@ +// PR c++/95789 +// { dg-do compile { target c++11 } } + +struct B { + int n; +}; + +template +struct A { + B& get() const { return f; } // { dg-error "binding reference" } + + B f; +}; + +int main() { + A a; + a.f = {}; + + a.get().n = 10; + if (a.f.n != 0) + __builtin_abort(); +} base-commit: 0164e59835de81d758fd4c56248ad7a46435fbfa -- Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA