diff options
author | Patrick Palka <ppalka@gcc.gnu.org> | 2016-01-19 00:19:16 +0000 |
---|---|---|
committer | Patrick Palka <ppalka@gcc.gnu.org> | 2016-01-19 00:19:16 +0000 |
commit | 17c15cb932563bb814865c39abc2b952c7707f79 (patch) | |
tree | c8fda91b6b8fbccdc143d90c1d753def47ac5deb /gcc/cp | |
parent | 49f8a19186f939a7561cb2bae31ffa67c649c606 (diff) | |
download | gcc-17c15cb932563bb814865c39abc2b952c7707f79.zip gcc-17c15cb932563bb814865c39abc2b952c7707f79.tar.gz gcc-17c15cb932563bb814865c39abc2b952c7707f79.tar.bz2 |
Fix the remaining PR c++/24666 blockers (arrays decay to pointers too early)
gcc/cp/ChangeLog:
PR c++/11858
PR c++/24663
PR c++/24664
* decl.c (grokdeclarator): Don't decay array parameter type to
a pointer type if it's dependent.
(grokparms): Invoke strip_top_quals instead of directly invoking
cp_build_qualified_type.
* pt.c (decay_dependent_array_parm_type): New static function.
(type_unification_real): Call decay_dependent_array_parm_type
to decay a dependent array parameter type to its corresponding
pointer type before unification.
(more_specialized_fn): Likewise.
(get_bindings): Likewise.
* tree.c (cp_build_qualified_type): Trivial typofix in
documentation.
gcc/testsuite/ChangeLog:
PR c++/11858
PR c++/24663
PR c++/24664
* g++.dg/template/pr11858.C: New test.
* g++.dg/template/pr24663.C: New test.
* g++.dg/template/unify12.C: New test.
* g++.dg/template/unify13.C: New test.
* g++.dg/template/unify14.C: New test.
* g++.dg/template/unify15.C: New test.
* g++.dg/template/unify16.C: New test.
* g++.dg/template/unify17.C: New test.
From-SVN: r232547
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/cp/decl.c | 12 | ||||
-rw-r--r-- | gcc/cp/pt.c | 27 | ||||
-rw-r--r-- | gcc/cp/tree.c | 2 |
4 files changed, 54 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9325bb0..87b4cca 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,21 @@ +2016-01-18 Patrick Palka <ppalka@gcc.gnu.org> + + PR c++/11858 + PR c++/24663 + PR c++/24664 + * decl.c (grokdeclarator): Don't decay array parameter type to + a pointer type if it's dependent. + (grokparms): Invoke strip_top_quals instead of directly invoking + cp_build_qualified_type. + * pt.c (decay_dependent_array_parm_type): New static function. + (type_unification_real): Call decay_dependent_array_parm_type + to decay a dependent array parameter type to its corresponding + pointer type before unification. + (more_specialized_fn): Likewise. + (get_bindings): Likewise. + * tree.c (cp_build_qualified_type): Trivial typofix in + documentation. + 2016-01-18 Jason Merrill <jason@redhat.com> * cp-gimplify.c (cp_fold) [CONSTRUCTOR]: Don't clobber the input. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index df95133..187390d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10898,8 +10898,13 @@ grokdeclarator (const cp_declarator *declarator, if (TREE_CODE (type) == ARRAY_TYPE) { - /* Transfer const-ness of array into that of type pointed to. */ - type = build_pointer_type (TREE_TYPE (type)); + /* Withhold decaying a dependent array type so that that during + instantiation we can detect type deduction failure cases such as + creating an array of void, creating a zero-size array, etc. */ + if (dependent_type_p (type)) + ; + else + type = build_pointer_type (TREE_TYPE (type)); type_quals = TYPE_UNQUALIFIED; array_parameter_p = true; } @@ -11696,7 +11701,8 @@ grokparms (tree parmlist, tree *parms) /* Top-level qualifiers on the parameters are ignored for function types. */ - type = cp_build_qualified_type (type, 0); + type = strip_top_quals (type); + if (TREE_CODE (type) == METHOD_TYPE) { error ("parameter %qD invalidly declared method type", decl); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 403c5ac..866b4b1 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17729,6 +17729,23 @@ fn_type_unification (tree fn, return r; } +/* TYPE is the type of a function parameter. If TYPE is a (dependent) + ARRAY_TYPE, return the corresponding POINTER_TYPE to which it decays. + Otherwise return TYPE. (We shouldn't see non-dependent ARRAY_TYPE + parameters because they get decayed as soon as they are declared.) */ + +static tree +decay_dependent_array_parm_type (tree type) +{ + if (TREE_CODE (type) == ARRAY_TYPE) + { + gcc_assert (uses_template_parms (type)); + return type_decays_to (type); + } + + return type; +} + /* Adjust types before performing type deduction, as described in [temp.deduct.call] and [temp.deduct.conv]. The rules in these two sections are symmetric. PARM is the type of a function parameter @@ -18167,6 +18184,8 @@ type_unification_real (tree tparms, arg = args[ia]; ++ia; + parm = decay_dependent_array_parm_type (parm); + if (unify_one_argument (tparms, targs, parm, arg, subr, strict, explain_p)) return 1; @@ -20169,6 +20188,9 @@ more_specialized_fn (tree pat1, tree pat2, int len) len = 0; } + arg1 = decay_dependent_array_parm_type (arg1); + arg2 = decay_dependent_array_parm_type (arg2); + if (TREE_CODE (arg1) == REFERENCE_TYPE) { ref1 = TYPE_REF_IS_RVALUE (arg1) + 1; @@ -20454,7 +20476,10 @@ get_bindings (tree fn, tree decl, tree explicit_args, bool check_rettype) for (arg = decl_arg_types, ix = 0; arg != NULL_TREE && arg != void_list_node; arg = TREE_CHAIN (arg), ++ix) - args[ix] = TREE_VALUE (arg); + { + args[ix] = TREE_VALUE (arg); + args[ix] = decay_dependent_array_parm_type (args[ix]); + } if (fn_type_unification (fn, explicit_args, targs, args, ix, diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index d4cf310..e2123ac 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1012,7 +1012,7 @@ c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */, arrays correctly. In particular, if TYPE is an array of T's, and TYPE_QUALS is non-empty, returns an array of qualified T's. - FLAGS determines how to deal with ill-formed qualifications. If + COMPLAIN determines how to deal with ill-formed qualifications. If tf_ignore_bad_quals is set, then bad qualifications are dropped (this is permitted if TYPE was introduced via a typedef or template type parameter). If bad qualifications are dropped and tf_warning |