aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2018-01-23 16:23:53 -0500
committerJason Merrill <jason@gcc.gnu.org>2018-01-23 16:23:53 -0500
commitd78201d30c7c5a8f15f0265d64386233e134fb7d (patch)
tree008dba49991a80ec4ff89d859da2dda52b3ec9d6 /gcc
parent7c719d0849416861fa96317ade2e2035d6ea071b (diff)
downloadgcc-d78201d30c7c5a8f15f0265d64386233e134fb7d.zip
gcc-d78201d30c7c5a8f15f0265d64386233e134fb7d.tar.gz
gcc-d78201d30c7c5a8f15f0265d64386233e134fb7d.tar.bz2
PR c++/83947 - ICE with auto declarations.
* pt.c (do_auto_deduction): Don't deduce from an auto decl. * decl.c (undeduced_auto_decl): Limit to vars and fns. From-SVN: r257000
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/decl.c8
-rw-r--r--gcc/cp/pt.c4
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/auto-fn46.C6
4 files changed, 21 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1f26155..9c2cba9 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-23 Jason Merrill <jason@redhat.com>
+
+ PR c++/83947 - ICE with auto declarations.
+ * pt.c (do_auto_deduction): Don't deduce from an auto decl.
+ * decl.c (undeduced_auto_decl): Limit to vars and fns.
+
2018-01-23 David Malcolm <dmalcolm@redhat.com>
PR c++/83974
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5f197ef..1970865 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -16195,15 +16195,17 @@ fndecl_declared_return_type (tree fn)
return TREE_TYPE (TREE_TYPE (fn));
}
-/* Returns true iff DECL was declared with an auto type and it has
- not yet been deduced to a real type. */
+/* Returns true iff DECL is a variable or function declared with an auto type
+ that has not yet been deduced to a real type. */
bool
undeduced_auto_decl (tree decl)
{
if (cxx_dialect < cxx11)
return false;
- return type_uses_auto (TREE_TYPE (decl));
+ return ((VAR_OR_FUNCTION_DECL_P (decl)
+ || TREE_CODE (decl) == TEMPLATE_DECL)
+ && type_uses_auto (TREE_TYPE (decl)));
}
/* Complain if DECL has an undeduced return type. */
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index fe64b06..d39b54e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -25884,6 +25884,10 @@ do_auto_deduction (tree type, tree init, tree auto_node,
from ahead of time isn't worth the trouble. */
return type;
+ /* Similarly, we can't deduce from another undeduced decl. */
+ if (init && undeduced_auto_decl (init))
+ return type;
+
if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
/* C++17 class template argument deduction. */
return do_class_deduction (type, tmpl, init, flags, complain);
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn46.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn46.C
new file mode 100644
index 0000000..120a4dd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn46.C
@@ -0,0 +1,6 @@
+// PR c++/83947
+// { dg-do compile { target c++14 } }
+
+auto f ();
+template < int > auto g (f); // { dg-error "before deduction" }
+auto h = g < 0 > ();