From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id BA419398C81A; Thu, 17 Sep 2020 16:47:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA419398C81A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600361234; bh=8iCXMO+PFB5hAekVQ04wYOHOUVGhsv0eBoY09buJhz8=; h=From:To:Subject:Date:From; b=tkNIxfX/4DC7jFZNfp+YdgIt+L7qHAg6aTEN+x/2YvmjrxfJplGey/KLkhN+n8RpF OYF8bVGCyhhESMKHGvVoqxGj21SIvSfw9v0Yld59kP2zJyNagdBz6Ewz4bqVnOQv2w wWplFIMPT0htA5qEjMaECQl3AZnMBbtU1Nch6oTs= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] PR c++/89831 - error with qualified-id in const member function. X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/vendors/redhat/heads/gcc-8-branch X-Git-Oldrev: 2f29510b2c89cddcf3c2707e3a6ef7407c226166 X-Git-Newrev: 59c76c064a74c04266d8365800c0b8e2cc967da9 Message-Id: <20200917164714.BA419398C81A@sourceware.org> Date: Thu, 17 Sep 2020 16:47:14 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 16:47:14 -0000 https://gcc.gnu.org/g:59c76c064a74c04266d8365800c0b8e2cc967da9 commit 59c76c064a74c04266d8365800c0b8e2cc967da9 Author: Jason Merrill Date: Tue Feb 25 13:37:18 2020 -0500 PR c++/89831 - error with qualified-id in const member function. Since the fix for 15272 we were remembering the wrong function to use at instantiation time, because the type of the SCOPE_REF didn't reflect the cv-quals of 'this'. Conveniently, we can fix this by simplifying the code. gcc/cp/ChangeLog 2020-02-25 Jason Merrill PR c++/89831 - error with qualified-id in const member function. * semantics.c (finish_non_static_data_member): Use object cv-quals in scoped case, too. Diff: --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/semantics.c | 19 +++++++++---------- gcc/testsuite/g++.dg/template/scope6.C | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4deaca672ca..f963baa5122 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-02-25 Jason Merrill + + PR c++/89831 - error with qualified-id in const member function. + * semantics.c (finish_non_static_data_member): Use object cv-quals + in scoped case, too. + 2020-02-25 Jason Merrill PR c++/88380 - wrong-code with flexible array and NSDMI. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 96849e76171..5099215ab5b 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1844,7 +1844,7 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) if (current_class_ptr) TREE_USED (current_class_ptr) = 1; - if (processing_template_decl && !qualifying_scope) + if (processing_template_decl) { tree type = TREE_TYPE (decl); @@ -1865,17 +1865,16 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) type = cp_build_qualified_type (type, quals); } - ret = (convert_from_reference - (build_min (COMPONENT_REF, type, object, decl, NULL_TREE))); + if (qualifying_scope) + /* Wrap this in a SCOPE_REF for now. */ + ret = build_qualified_name (type, qualifying_scope, decl, + /*template_p=*/false); + else + ret = (convert_from_reference + (build_min (COMPONENT_REF, type, object, decl, NULL_TREE))); } /* If PROCESSING_TEMPLATE_DECL is nonzero here, then - QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF - for now. */ - else if (processing_template_decl) - ret = build_qualified_name (TREE_TYPE (decl), - qualifying_scope, - decl, - /*template_p=*/false); + QUALIFYING_SCOPE is also non-null. */ else { tree access_type = TREE_TYPE (object); diff --git a/gcc/testsuite/g++.dg/template/scope6.C b/gcc/testsuite/g++.dg/template/scope6.C new file mode 100644 index 00000000000..6d28fb2ec9e --- /dev/null +++ b/gcc/testsuite/g++.dg/template/scope6.C @@ -0,0 +1,17 @@ +// PR c++/89831 + +struct Q { + int operator[](int i) { return 0; } + int operator[](int i) const { return 0; } +}; + +struct Base { + Q x; +}; +struct X : public Base { + template + void f(T) const { + int q = Base::x[0]; + } +}; +int main() { X().f(3); }