From: Jason Merrill Date: Fri, 21 Nov 2014 00:47:50 +0000 (-0500) Subject: re PR c++/63658 (Using class reference as template parameter causes compilation to... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a663ce5a831198b5ef99cbc0b7205a2d9a37a574;p=gcc.git re PR c++/63658 (Using class reference as template parameter causes compilation to fail) 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 305565fa350..ee431a1091d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2014-11-20 Jason Merrill + 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 diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 576ad1d1978..4c63df042fa 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 05ca7062865..71b7af1c206 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 00000000000..983f627887f --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ref9.C @@ -0,0 +1,15 @@ +// PR c++/63658 + +struct Descriptor {}; + +template +struct foo +{ + void size (); +}; + +Descriptor g_descriptor = {}; + +template<> void foo::size() +{ +}