From d816a3ba71e05342e7ddbf9c0a7b0bb67d05dc12 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 1 Jul 2011 16:24:25 -0400 Subject: [PATCH] re PR c++/48593 (Wrong return type when applying address operator to inherited, template dependend member, using a typedef) PR c++/48593 * pt.c (tsubst_qualified_id): Check PTRMEM_OK_P. * tree.c (build_qualified_name): Set PTRMEM_OK_P. * semantics.c (finish_parenthesized_expr): Clear PTRMEM_OK_P on SCOPE_REF, too. * cp-tree.h (PTRMEM_OK_P): Apply to SCOPE_REF, too. (QUALIFIED_NAME_IS_TEMPLATE): Switch to lang flag 1. From-SVN: r175765 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/cp-tree.h | 8 ++++---- gcc/cp/pt.c | 2 +- gcc/cp/semantics.c | 3 ++- gcc/cp/tree.c | 1 + gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/template/qualified-id4.C | 20 +++++++++++++++++++ 7 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/qualified-id4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ac7edddfe28..5cfdfbf9b0e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,13 @@ 2011-07-01 Jason Merrill + PR c++/48593 + * pt.c (tsubst_qualified_id): Check PTRMEM_OK_P. + * tree.c (build_qualified_name): Set PTRMEM_OK_P. + * semantics.c (finish_parenthesized_expr): Clear PTRMEM_OK_P on + SCOPE_REF, too. + * cp-tree.h (PTRMEM_OK_P): Apply to SCOPE_REF, too. + (QUALIFIED_NAME_IS_TEMPLATE): Switch to lang flag 1. + PR c++/48883 PR c++/49609 * pt.c (resolve_nondeduced_context): Call mark_used. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ef25c97aafb..357295c8401 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -53,7 +53,7 @@ c-common.h, not after. TREE_INDIRECT_USING (in NAMESPACE_DECL). CLEANUP_P (in TRY_BLOCK) AGGR_INIT_VIA_CTOR_P (in AGGR_INIT_EXPR) - PTRMEM_OK_P (in ADDR_EXPR, OFFSET_REF) + PTRMEM_OK_P (in ADDR_EXPR, OFFSET_REF, SCOPE_REF) PAREN_STRING_LITERAL (in STRING_CST) DECL_PRETTY_FUNCTION_P (in VAR_DECL) KOENIG_LOOKUP_P (in CALL_EXPR) @@ -62,7 +62,6 @@ c-common.h, not after. STMT_EXPR_NO_SCOPE (in STMT_EXPR) BIND_EXPR_TRY_BLOCK (in BIND_EXPR) TYPENAME_IS_ENUM_P (in TYPENAME_TYPE) - QUALIFIED_NAME_IS_TEMPLATE (in SCOPE_REF) OMP_FOR_GIMPLIFYING_P (in OMP_FOR) BASELINK_QUALIFIED_P (in BASELINK) TARGET_EXPR_IMPLICIT_P (in TARGET_EXPR) @@ -86,6 +85,7 @@ c-common.h, not after. LAMBDA_EXPR_MUTABLE_P (in LAMBDA_EXPR) DECLTYPE_FOR_LAMBDA_RETURN (in DECLTYPE_TYPE) DECL_FINAL_P (in FUNCTION_DECL) + QUALIFIED_NAME_IS_TEMPLATE (in SCOPE_REF) 2: IDENTIFIER_OPNAME_P (in IDENTIFIER_NODE) ICS_THIS_FLAG (in _CONV) DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (in VAR_DECL) @@ -3354,7 +3354,7 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) /* Indicates when overload resolution may resolve to a pointer to member function. [expr.unary.op]/3 */ #define PTRMEM_OK_P(NODE) \ - TREE_LANG_FLAG_0 (TREE_CHECK2 ((NODE), ADDR_EXPR, OFFSET_REF)) + TREE_LANG_FLAG_0 (TREE_CHECK3 ((NODE), ADDR_EXPR, OFFSET_REF, SCOPE_REF)) /* Get the POINTER_TYPE to the METHOD_TYPE associated with this pointer to member function. TYPE_PTRMEMFUNC_P _must_ be true, @@ -3801,7 +3801,7 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) /* True for a SCOPE_REF iff the "template" keyword was used to indicate that the qualified name denotes a template. */ #define QUALIFIED_NAME_IS_TEMPLATE(NODE) \ - (TREE_LANG_FLAG_0 (SCOPE_REF_CHECK (NODE))) + (TREE_LANG_FLAG_1 (SCOPE_REF_CHECK (NODE))) /* True for an OMP_ATOMIC that has dependent parameters. These are stored as an expr in operand 1, and integer_zero_node in operand 0. */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 947e19e6283..57431598148 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11344,7 +11344,7 @@ tsubst_qualified_id (tree qualified_id, tree args, expr = (adjust_result_of_qualified_name_lookup (expr, scope, current_class_type)); expr = (finish_qualified_id_expr - (scope, expr, done, address_p, + (scope, expr, done, address_p && PTRMEM_OK_P (qualified_id), QUALIFIED_NAME_IS_TEMPLATE (qualified_id), /*template_arg_p=*/false)); } diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index a704aa3182a..e29705c5782 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1504,7 +1504,8 @@ finish_parenthesized_expr (tree expr) /* This inhibits warnings in c_common_truthvalue_conversion. */ TREE_NO_WARNING (expr) = 1; - if (TREE_CODE (expr) == OFFSET_REF) + if (TREE_CODE (expr) == OFFSET_REF + || TREE_CODE (expr) == SCOPE_REF) /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be enclosed in parentheses. */ PTRMEM_OK_P (expr) = 0; diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 678c7ef9bf1..dcd85e40c98 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1411,6 +1411,7 @@ build_qualified_name (tree type, tree scope, tree name, bool template_p) return error_mark_node; t = build2 (SCOPE_REF, type, scope, name); QUALIFIED_NAME_IS_TEMPLATE (t) = template_p; + PTRMEM_OK_P (t) = true; if (type) t = convert_from_reference (t); return t; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 903e0fb22f1..a201db2df80 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2011-07-01 Jason Merrill + PR c++/48593 + * g++.dg/template/qualified-id4.C: New. + PR c++/48883 * g++.dg/template/explicit-args4.C: New. diff --git a/gcc/testsuite/g++.dg/template/qualified-id4.C b/gcc/testsuite/g++.dg/template/qualified-id4.C new file mode 100644 index 00000000000..0d97cb868cb --- /dev/null +++ b/gcc/testsuite/g++.dg/template/qualified-id4.C @@ -0,0 +1,20 @@ +// PR c++/48593 + +template struct foo +{ + T data; +}; + +template struct bar: public foo +{ + void some_func() + { + T* ptr = &(foo::data); + } +}; + +int main() +{ + bar().some_func(); +} + -- 2.30.2