This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/63658 (reference non-type template parameters)


My patch for c++/58606 changed the internal representation of reference template arguments to include the dereference in some places, but not enough.

Tested x86_64-cp-linux-gnu, applying to trunk and 4.9.
commit f7ea463fa794117000ef8495cb87d8c054323c7e
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Nov 20 08:46:48 2014 -0500

    	PR c++/63658
    	* pt.c (convert_nontype_argument): Call convert_from_reference.
    	(check_instantiated_arg): Don't be confused by reference refs.
    	(unify): Look through reference refs on the arg, too.
    	* mangle.c (write_template_arg): Look through reference refs.

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 576ad1d..4c63df0 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3086,6 +3086,8 @@ write_template_arg (tree node)
 	}
     }
 
+  if (REFERENCE_REF_P (node))
+    node = TREE_OPERAND (node, 0);
   if (TREE_CODE (node) == NOP_EXPR
       && TREE_CODE (TREE_TYPE (node)) == REFERENCE_TYPE)
     {
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 05ca706..71b7af1 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -6174,7 +6174,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
      right type?  */
   gcc_assert (same_type_ignoring_top_level_qualifiers_p
 	      (type, TREE_TYPE (expr)));
-  return expr;
+  return convert_from_reference (expr);
 }
 
 /* Subroutine of coerce_template_template_parms, which returns 1 if
@@ -15740,6 +15740,7 @@ check_instantiated_arg (tree tmpl, tree t, tsubst_flags_t complain)
      constant.  */
   else if (TREE_TYPE (t)
 	   && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (t))
+	   && !REFERENCE_REF_P (t)
 	   && !TREE_CONSTANT (t))
     {
       if (complain & tf_error)
@@ -18473,8 +18474,12 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
 
     case INDIRECT_REF:
       if (REFERENCE_REF_P (parm))
-	return unify (tparms, targs, TREE_OPERAND (parm, 0), arg,
-		      strict, explain_p);
+	{
+	  if (REFERENCE_REF_P (arg))
+	    arg = TREE_OPERAND (arg, 0);
+	  return unify (tparms, targs, TREE_OPERAND (parm, 0), arg,
+			strict, explain_p);
+	}
       /* FALLTHRU */
 
     default:
diff --git a/gcc/testsuite/g++.dg/template/ref9.C b/gcc/testsuite/g++.dg/template/ref9.C
new file mode 100644
index 0000000..983f627
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ref9.C
@@ -0,0 +1,15 @@
+// PR c++/63658
+
+struct Descriptor {};
+
+template <Descriptor & D>
+struct foo
+{
+  void size ();
+};
+
+Descriptor g_descriptor = {};
+
+template<> void foo<g_descriptor>::size()
+{
+}
commit fea8bb6d4f45b8b1388001e59ad73b3ba63f41ea
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Nov 20 09:37:50 2014 -0500

    	* error.c (dump_expr): Avoid printing (*&i) for references.

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 76f86cb..7d79771 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2299,7 +2299,13 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
 			    TREE_TYPE (ttype)))
 	  {
 	    if (TREE_CODE (ttype) == REFERENCE_TYPE)
-	      dump_unary_op (pp, "*", t, flags);
+	      {
+		STRIP_NOPS (op);
+		if (TREE_CODE (op) == ADDR_EXPR)
+		  dump_expr (pp, TREE_OPERAND (op, 0), flags);
+		else
+		  dump_unary_op (pp, "*", t, flags);
+	      }
 	    else
 	      dump_unary_op (pp, "&", t, flags);
 	  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]