Commit d78201d3 by Jason Merrill Committed by Jason Merrill

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
parent 7c719d08
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> 2018-01-23 David Malcolm <dmalcolm@redhat.com>
PR c++/83974 PR c++/83974
......
...@@ -16195,15 +16195,17 @@ fndecl_declared_return_type (tree fn) ...@@ -16195,15 +16195,17 @@ fndecl_declared_return_type (tree fn)
return TREE_TYPE (TREE_TYPE (fn)); return TREE_TYPE (TREE_TYPE (fn));
} }
/* Returns true iff DECL was declared with an auto type and it has /* Returns true iff DECL is a variable or function declared with an auto type
not yet been deduced to a real type. */ that has not yet been deduced to a real type. */
bool bool
undeduced_auto_decl (tree decl) undeduced_auto_decl (tree decl)
{ {
if (cxx_dialect < cxx11) if (cxx_dialect < cxx11)
return false; 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. */ /* Complain if DECL has an undeduced return type. */
......
...@@ -25884,6 +25884,10 @@ do_auto_deduction (tree type, tree init, tree auto_node, ...@@ -25884,6 +25884,10 @@ do_auto_deduction (tree type, tree init, tree auto_node,
from ahead of time isn't worth the trouble. */ from ahead of time isn't worth the trouble. */
return type; 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)) if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
/* C++17 class template argument deduction. */ /* C++17 class template argument deduction. */
return do_class_deduction (type, tmpl, init, flags, complain); return do_class_deduction (type, tmpl, init, flags, complain);
......
// PR c++/83947
// { dg-do compile { target c++14 } }
auto f ();
template < int > auto g (f); // { dg-error "before deduction" }
auto h = g < 0 > ();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment