aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2015-07-25 02:54:57 -0400
committerJason Merrill <jason@gcc.gnu.org>2015-07-25 02:54:57 -0400
commit0c0d447a96c1786e855782bd18f35f307e5ca2d8 (patch)
treed53edd2f41b84f2e97ddc5c2c4b716cd7f5fb73d /gcc
parent8edd0f66d80adb3950a35fc0dc47af2355c73fc4 (diff)
downloadgcc-0c0d447a96c1786e855782bd18f35f307e5ca2d8.zip
gcc-0c0d447a96c1786e855782bd18f35f307e5ca2d8.tar.gz
gcc-0c0d447a96c1786e855782bd18f35f307e5ca2d8.tar.bz2
re PR c++/64989 (constant-initialization of self-referencing array)
PR c++/64989 * pt.c (splice_late_return_type): Correct deduced return type for abbreviated function template. From-SVN: r226207
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c20
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/abbrev1.C11
3 files changed, 29 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index df805e6..39869df 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2015-07-24 Jason Merrill <jason@redhat.com>
+
+ PR c++/64989
+ * pt.c (splice_late_return_type): Correct deduced return type for
+ abbreviated function template.
+
2015-07-24 Richard Biener <rguenther@suse.de>
* init.c (build_vec_init): Build iterator bound in the same
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 5004883..971c98e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -22459,15 +22459,19 @@ do_auto_deduction (tree type, tree init, tree auto_node)
tree
splice_late_return_type (tree type, tree late_return_type)
{
- tree argvec;
+ if (is_auto (type))
+ {
+ if (late_return_type)
+ return late_return_type;
- if (late_return_type == NULL_TREE)
- return type;
- argvec = make_tree_vec (1);
- TREE_VEC_ELT (argvec, 0) = late_return_type;
- if (current_template_parms)
- argvec = add_to_template_args (current_template_args (), argvec);
- return tsubst (type, argvec, tf_warning_or_error, NULL_TREE);
+ tree idx = get_template_parm_index (type);
+ if (TEMPLATE_PARM_LEVEL (idx) <= processing_template_decl)
+ /* In an abbreviated function template we didn't know we were dealing
+ with a function template when we saw the auto return type, so update
+ it to have the correct level. */
+ return make_auto_1 (TYPE_IDENTIFIER (type));
+ }
+ return type;
}
/* Returns true iff TYPE is a TEMPLATE_TYPE_PARM representing 'auto' or
diff --git a/gcc/testsuite/g++.dg/cpp1z/abbrev1.C b/gcc/testsuite/g++.dg/cpp1z/abbrev1.C
new file mode 100644
index 0000000..68a0bf3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/abbrev1.C
@@ -0,0 +1,11 @@
+// PR c++/64969
+// { dg-options "-std=c++1z" }
+
+auto f1(auto x) { return *x; }
+decltype(auto) f2(auto x) { return *x; }
+auto f3(auto x) -> int { return *x; }
+
+int i;
+auto r1 = f1(&i);
+auto r2 = f2(&i);
+auto r3 = f3(&i);