Patchwork C++ PATCH for c++/48593 (&(T::m) being treated as pointer to member in template)

login
register
mail settings
Submitter Jason Merrill
Date July 1, 2011, 8:23 p.m.
Message ID <4E0E2CA4.1010805@redhat.com>
Download mbox | patch
Permalink /patch/102966/
State New
Headers show

Comments

Jason Merrill - July 1, 2011, 8:23 p.m.
We weren't preserving the parenthesis in the template context.  Oops.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 9108c3486dd1a408fdd7c64a0393aa5eec1e7a14
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jul 1 13:43:22 2011 -0400

    	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.

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index ef25c97..357295c 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 947e19e..5743159 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 a704aa3..e29705c 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 678c7ef..dcd85e4 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/g++.dg/template/qualified-id4.C b/gcc/testsuite/g++.dg/template/qualified-id4.C
new file mode 100644
index 0000000..0d97cb8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/qualified-id4.C
@@ -0,0 +1,20 @@ 
+// PR c++/48593
+
+template <typename T> struct foo
+{
+  T data;
+};
+
+template<typename T> struct bar: public foo<T>
+{
+  void some_func()
+  {
+    T* ptr = &(foo<T>::data);
+  }
+};
+
+int main()
+{
+  bar<int>().some_func();
+}
+