From: Jason Merrill Date: Fri, 19 Jul 2019 08:53:07 +0000 (-0400) Subject: PR c++/90098 - partial specialization and class non-type parms. X-Git-Tag: releases/gcc-9.2.0~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0385e9b466aa8d9ba79578b466316630540ee9b;p=thirdparty%2Fgcc.git PR c++/90098 - partial specialization and class non-type parms. A non-type template parameter of class type used in an expression has const-qualified type; the pt.c hunks deal with this difference from the unqualified type of the parameter declaration. WAhen we use such a parameter as an argument to another template, we don't want to confuse things by copying it, we should pass it straight through. And we might as well skip copying other classes in constant evaluation context in a template, too; we'll get the copy semantics at instantiation time. PR c++/90099 PR c++/90101 * call.c (build_converted_constant_expr_internal): Don't copy. * pt.c (process_partial_specialization): Allow VIEW_CONVERT_EXPR around class non-type parameter. (unify) [TEMPLATE_PARM_INDEX]: Ignore cv-quals. (invalid_nontype_parm_type_p): Check for dependent class type. From-SVN: r273597 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4b69396e7307..8621f5733be5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,14 @@ 2019-07-19 Jason Merrill + PR c++/90098 - partial specialization and class non-type parms. + PR c++/90099 + PR c++/90101 + * call.c (build_converted_constant_expr_internal): Don't copy. + * pt.c (process_partial_specialization): Allow VIEW_CONVERT_EXPR + around class non-type parameter. + (unify) [TEMPLATE_PARM_INDEX]: Ignore cv-quals. + (invalid_nontype_parm_type_p): Check for dependent class type. + PR c++/85552 - wrong instantiation of dtor for DMI. * typeck2.c (digest_nsdmi_init): Set tf_no_cleanup for direct-init. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 23898f0659fb..9e22a146a16a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4279,6 +4279,12 @@ build_converted_constant_expr_internal (tree type, tree expr, if (conv) { + /* Don't copy a class non-type template parameter. */ + if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue + && TREE_CODE (expr) == VIEW_CONVERT_EXPR + && TREE_CODE (TREE_OPERAND (expr, 0)) == TEMPLATE_PARM_INDEX) + conv = next_conversion (conv); + conv->check_narrowing = true; conv->check_narrowing_const_only = true; expr = convert_like (conv, expr, complain); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b9137aa0a829..7069e2f3047e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4953,7 +4953,8 @@ process_partial_specialization (tree decl) simple identifier' condition and also the `specialized non-type argument' bit. */ && TREE_CODE (arg) != TEMPLATE_PARM_INDEX - && !(REFERENCE_REF_P (arg) + && !((REFERENCE_REF_P (arg) + || TREE_CODE (arg) == VIEW_CONVERT_EXPR) && TREE_CODE (TREE_OPERAND (arg, 0)) == TEMPLATE_PARM_INDEX)) { if ((!packed_args && tpd.arg_uses_template_parms[i]) @@ -22379,9 +22380,11 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, /* Template-parameter dependent expression. Just accept it for now. It will later be processed in convert_template_argument. */ ; - else if (same_type_p (non_reference (TREE_TYPE (arg)), - non_reference (tparm))) - /* OK */; + else if (same_type_ignoring_top_level_qualifiers_p + (non_reference (TREE_TYPE (arg)), + non_reference (tparm))) + /* OK. Ignore top-level quals here because a class-type template + parameter object is const. */; else if ((strict & UNIFY_ALLOW_INTEGER) && CP_INTEGRAL_TYPE_P (tparm)) /* Convert the ARG to the type of PARM; the deduced non-type @@ -25233,6 +25236,8 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain) "with %<-std=c++2a%> or %<-std=gnu++2a%>"); return true; } + if (dependent_type_p (type)) + return false; if (!complete_type_or_else (type, NULL_TREE)) return true; if (!literal_type_p (type)) diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class18.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class18.C new file mode 100644 index 000000000000..22f47884d08e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class18.C @@ -0,0 +1,17 @@ +// PR c++/90101 +// { dg-do compile { target c++2a } } + +template +struct A; + +template typename List> +struct A> {}; + +template typename List, auto V> +struct A> {}; + +template +struct B {}; + +struct X { int value; }; +A> a2; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class19.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class19.C new file mode 100644 index 000000000000..91267aca3839 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class19.C @@ -0,0 +1,13 @@ +// PR c++/90099 +// { dg-do compile { target c++2a } } + +struct Unit { + int value; + // auto operator<=>(const Unit&) = default; +}; + +template +struct X {}; + +template +struct X {}; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class20.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class20.C new file mode 100644 index 000000000000..5d3479c345e9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class20.C @@ -0,0 +1,13 @@ +// PR c++/90098 +// { dg-do compile { target c++2a } } + +struct A { + int value; + // auto operator<=>(const A&) = default; +}; + +template +struct Z {}; + +template +struct Z {}; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class21.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class21.C new file mode 100644 index 000000000000..c58fe05b9dd9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class21.C @@ -0,0 +1,10 @@ +// PR c++/90101 +// { dg-do compile { target c++2a } } + +template +struct A{}; + +template> +struct B {}; + +B<2,A<2>{}> b; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class22.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class22.C new file mode 100644 index 000000000000..026855f0bc65 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class22.C @@ -0,0 +1,21 @@ +// PR c++/90100 +// { dg-do compile { target c++2a } } + +template +inline constexpr bool is_nontype_list = false; + +template typename T, auto... NonTypes> +inline constexpr bool is_nontype_list> = true; + +// works +template +struct A {}; + +static_assert(is_nontype_list>); + +// fails +struct X { + int v; +}; + +static_assert(is_nontype_list>);