From: Jason Merrill Date: Wed, 27 Mar 2019 20:39:19 +0000 (-0400) Subject: PR c++/89831 - error with qualified-id in const member function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dd03c093bcc932fa7ec09e2f0e5662f6d8f429db;p=gcc.git 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. * semantics.c (finish_non_static_data_member): Use object cv-quals in scoped case, too. From-SVN: r269977 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bdd5211777b..9803ef947f8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-03-27 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. + PR c++/89421 - ICE with lambda in template parameter list. * parser.c (cp_parser_lambda_expression): Also reject a lambda in a template parameter list before C++20. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index fea269657f9..a08a2a57f5f 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1861,7 +1861,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); @@ -1882,17 +1882,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); }