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 B6BDC3856083 for ; Thu, 26 May 2022 18:34:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B6BDC3856083 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-aLrVFIrFP-KHzFwNYFy0oQ-1; Thu, 26 May 2022 14:34:53 -0400 X-MC-Unique: aLrVFIrFP-KHzFwNYFy0oQ-1 Received: by mail-qv1-f70.google.com with SMTP id l15-20020a056214028f00b004625e7032easo1684766qvv.9 for ; Thu, 26 May 2022 11:34:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SDTU0GmANW2p8fTcU+Y/jc59QIoJFgecSG6sOQiuKKM=; b=UnR+xPLvWOl2vixbTm6NR6FihsDDbfteJI1VFmU9SwiBuisT7b563q51pXffoRcjAU L8mDEAg+qNQcXn9g/4xgkFGZ6AHXqe2Cw5MCVGuQQQnJZ5mdb3Gy48KUdTtOtNxVzzsa 7wLV+UIFb4vgaFu8Zed45siDhzGUcg1h2YNGkrL8hIeMObbwcTcnQ6oC2O7z6qdW0S1J Q38XWUkPr1UW5Wk03dEpymDovQlLNVygcPja1F74pg+mBoZkCfaZSKmf3RmCu3EJmPmz dXUO814q4QWhoRgn/K23f2BVopkivzF6tmdkEAP6sClwGN9h+Q3aq1QWnOi44wnQi7uP /ppA== X-Gm-Message-State: AOAM531GZeuWKt2Z4iYHPYXm8rw26+dGpfUn4IRH7/iAXAsQIuq8oXxN xLFf59xUkhJ113otJOw+ba0DCcyhhF911iEw8+nhpDtRGL/LaHNWSX/5EPXrzDAzBYMpvwAhu8g CMIk+Npqc6Zbf6s/iXKQWm3sSTnccw1fLP9iAWnOMymer1/MnPWQ1qReXQae3PbpL0AI= X-Received: by 2002:ac8:7f87:0:b0:2f9:e10:2930 with SMTP id z7-20020ac87f87000000b002f90e102930mr30336928qtj.673.1653590092725; Thu, 26 May 2022 11:34:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp+DkESqMMtv+pDQc57EAfSsGik2bXezn/hMgT3OpHZxVBLK0wuAHKCuxr4EIJEWqRA+k/SQ== X-Received: by 2002:ac8:7f87:0:b0:2f9:e10:2930 with SMTP id z7-20020ac87f87000000b002f90e102930mr30336905qtj.673.1653590092371; Thu, 26 May 2022 11:34:52 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id h124-20020a37b782000000b0069fc13ce1dfsm1556979qkf.16.2022.05.26.11.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 11:34:51 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: cv-quals of dummy obj for non-dep memfn call [PR105637] Date: Thu, 26 May 2022 14:34:50 -0400 Message-Id: <20220526183450.2331967-1-ppalka@redhat.com> X-Mailer: git-send-email 2.36.1.182.g6afdb07b7b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.6 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_LOW, 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: Thu, 26 May 2022 18:34:56 -0000 Here we expect the calls to BaseClass::baseDevice resolve to the second, third and fourth overloads respectively in light of the cv-qualifiers of 'this' in each case. But ever since r12-6075-g2decd2cabe5a4f, the calls incorrectly resolve to the first overload at instantiation time. This happens because the calls to BaseClass::baseDevice are all deemed non-dependent (ever since r7-755-g23cb72663051cd made us ignore the dependentness of 'this' when considering the dependence of a non-static memfn call), hence we end up checking the call ahead of time, using as the object argument a dummy object of type BaseClass. Since this object argument is cv-unqualified, the calls incoherently resolve to the first overload of baseDevice. Before r12-6075, this incorrect result would just get silently discarded and we'd end up redoing OR at instantiation time using 'this' as the object argument. But after r12-6075, we now reuse this incorrect result at instantiation time. This patch fixes this by making finish_call_expr request from maybe_dummy_object a cv-qualified object consistent with the cv-quals of 'this'. That way, ahead of time OR using a dummy object will give us the right answer and we could safely reuse it at instantiation time. NB: r7-755 is also the cause of the related issue PR105742. Not sure if there's a fix that could resolve both PRs at once.. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/12? PR c++/105637 gcc/cp/ChangeLog: * semantics.cc (finish_call_expr): Pass a cv-qualified object type to maybe_dummy_object that is consistent with the cv-qualifiers of 'this' if available. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent23.C: New test. --- gcc/cp/semantics.cc | 15 ++++++++--- .../g++.dg/template/non-dependent23.C | 25 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent23.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index cd7a2818feb..1d9348c6cf1 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -2802,16 +2802,25 @@ finish_call_expr (tree fn, vec **args, bool disallow_virtual, [class.access.base] says that we need to convert 'this' to B* as part of the access, so we pass 'B' to maybe_dummy_object. */ + tree object_type = BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)); if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn))) { /* A constructor call always uses a dummy object. (This constructor call which has the form A::A () is actually invalid and we are going to reject it later in build_new_method_call.) */ - object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn))); + object = build_dummy_object (object_type); } else - object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), - NULL); + { + if (current_class_ref) + { + /* Make sure that if maybe_dummy_object gives us a dummy object, + it'll have the same cv-quals as '*this'. */ + int quals = cp_type_quals (TREE_TYPE (current_class_ref)); + object_type = cp_build_qualified_type (object_type, quals); + } + object = maybe_dummy_object (object_type, NULL); + } result = build_new_method_call (object, fn, args, NULL_TREE, (disallow_virtual diff --git a/gcc/testsuite/g++.dg/template/non-dependent23.C b/gcc/testsuite/g++.dg/template/non-dependent23.C new file mode 100644 index 00000000000..ef95c591b75 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent23.C @@ -0,0 +1,25 @@ +// PR c++/105637 + +struct BaseClass { + void baseDevice(); // #1 + void baseDevice() const; // #2 + void baseDevice() volatile; // #3 + void baseDevice() const volatile; // #4 +}; + +template +struct TopClass : T { + void failsToCompile() const { + BaseClass::baseDevice(); // should select #2, not #1 + } + + void failsToCompile() volatile { + BaseClass::baseDevice(); // should select #3, not #1 + } + + void failsToCompile() const volatile { + BaseClass::baseDevice(); // should select #4, not #1 + } +}; + +template struct TopClass; -- 2.36.1.182.g6afdb07b7b