re PR c++/63658 (Using class reference as template parameter causes compilation to...
authorJason Merrill <jason@redhat.com>
Fri, 21 Nov 2014 00:47:50 +0000 (19:47 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 21 Nov 2014 00:47:50 +0000 (19:47 -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.

From-SVN: r217900

gcc/cp/ChangeLog
gcc/cp/mangle.c
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/ref9.C [new file with mode: 0644]

index 305565fa350237551f7def4e58cb38b20d5482a2..ee431a1091d0a5c93aa2265a88759b2119ab6488 100644 (file)
@@ -1,5 +1,11 @@
 2014-11-20  Jason Merrill  <jason@redhat.com>
 
+       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.
+
        * error.c (dump_expr): Avoid printing (*&i) for references.
 
 2014-11-20  Ville Voutilainen  <ville.voutilainen@gmail.com>
index 576ad1d19780d1dea2cdeb16efbe25487a4866f8..4c63df042faf9391d702e2803cd9c825485d904c 100644 (file)
@@ -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)
     {
index 05ca70628658e3dd6fb5bd3459869dfad9589860..71b7af1c206ff8862cf8d72981c51e07eb49f5ac 100644 (file)
@@ -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 (file)
index 0000000..983f627
--- /dev/null
@@ -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()
+{
+}