Message ID | CADzB+2m3J9W_c5hFGDgCfpCY8Ttq8jv3qFGz2ZshsKcG5xo=zw@mail.gmail.com |
---|---|
State | New |
Headers | show |
Series | C++ PATCH for c++/84720, ICE with rvalue ref template parameter | expand |
On Tue, Mar 13, 2018 at 2:54 PM, Jason Merrill <jason@redhat.com> wrote: > It's unclear to me that it is ever possible to instantiate a template > taking an rvalue ref parameter, but I guess we might as well handle it > properly. ...except that such parameters are actually ill-formed, so we should reject. commit dea7cfdf2f1e7f17befbe3987badba9f74a6b2b9 Author: Jason Merrill <jason@redhat.com> Date: Fri Mar 16 14:01:14 2018 -0400 PR c++/84720 - ICE with rvalue ref non-type argument. * pt.c (invalid_nontype_parm_type_p): Prohibit rvalue reference. (convert_nontype_argument): Revert earlier change. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6c96424152e..f7b1b0dd9aa 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -23985,7 +23985,10 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain) { if (INTEGRAL_OR_ENUMERATION_TYPE_P (type)) return false; - else if (POINTER_TYPE_P (type)) + else if (TYPE_PTR_P (type)) + return false; + else if (TREE_CODE (type) == REFERENCE_TYPE + && !TYPE_REF_IS_RVALUE (type)) return false; else if (TYPE_PTRMEM_P (type)) return false; diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-targ1.C b/gcc/testsuite/g++.dg/cpp0x/rv-targ1.C index b8e0daba0f7..06516dfa2b9 100644 --- a/gcc/testsuite/g++.dg/cpp0x/rv-targ1.C +++ b/gcc/testsuite/g++.dg/cpp0x/rv-targ1.C @@ -1,7 +1,7 @@ // PR c++/84720 // { dg-do compile { target c++11 } } -template<int &&> +template<int &&> // { dg-error "not a valid type" } struct a { template<typename...> static void b() {
commit 78c6cbb0e9fb5796825dc49891c7921e9270c09e Author: Jason Merrill <jason@redhat.com> Date: Tue Mar 13 14:25:00 2018 -0400 PR c++/84720 - ICE with rvalue ref non-type argument. * pt.c (convert_nontype_argument): Handle rvalue references. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index fdc1c9a7a75..a16aef6bf58 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6932,11 +6932,18 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) return NULL_TREE; } - if (!lvalue_p (expr)) + if (!glvalue_p (expr) + || TYPE_REF_IS_RVALUE (type) != xvalue_p (expr)) { if (complain & tf_error) - error ("%qE is not a valid template argument for type %qT " - "because it is not an lvalue", expr, type); + { + if (TYPE_REF_IS_RVALUE (type)) + error ("%qE is not a valid template argument for type %qT " + "because it is not an xvalue", expr, type); + else + error ("%qE is not a valid template argument for type %qT " + "because it is not an lvalue", expr, type); + } return NULL_TREE; } diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-targ1.C b/gcc/testsuite/g++.dg/cpp0x/rv-targ1.C new file mode 100644 index 00000000000..b8e0daba0f7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-targ1.C @@ -0,0 +1,10 @@ +// PR c++/84720 +// { dg-do compile { target c++11 } } + +template<int &&> +struct a { + template<typename...> + static void b() { + b(); + } +};