public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] PR c++/89831 - error with qualified-id in const member function.
@ 2020-09-17 16:47 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 16:47 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:59c76c064a74c04266d8365800c0b8e2cc967da9
commit 59c76c064a74c04266d8365800c0b8e2cc967da9
Author: Jason Merrill <jason@redhat.com>
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 <jason@redhat.com>
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 <jason@redhat.com>
+
+ 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 <jason@redhat.com>
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 <typename T>
+ void f(T) const {
+ int q = Base::x[0];
+ }
+};
+int main() { X().f(3); }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-17 16:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 16:47 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] PR c++/89831 - error with qualified-id in const member function Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).