diff options
author | Jason Merrill <jason@redhat.com> | 2022-05-24 17:37:58 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-05-25 11:09:10 -0400 |
commit | 850a9ce8bcca59c7efabcdeeca14c5bd905e8363 (patch) | |
tree | 8e9fe808f5f9be98eb1436a45df1f1376d820f5a /gcc | |
parent | 8c9c92f8079589730708ce831a86e01d510d9db4 (diff) | |
download | gcc-850a9ce8bcca59c7efabcdeeca14c5bd905e8363.zip gcc-850a9ce8bcca59c7efabcdeeca14c5bd905e8363.tar.gz gcc-850a9ce8bcca59c7efabcdeeca14c5bd905e8363.tar.bz2 |
c++: deduction from auto fn [PR105623]
Since my patch for PR90451, we defer mark_used of single functions as late
as possible. And since my r12-1273, we keep BASELINK from lookup around
rather than reconstruct it later. These both made us try to instantiate g
with a function type that still had 'auto' as its return type.
PR c++/105623
gcc/cp/ChangeLog:
* decl2.cc (mark_used): Copy type from fn to BASELINK.
* pt.cc (unify_one_argument): Call mark_single_function.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/auto-fn62.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/decl2.cc | 11 | ||||
-rw-r--r-- | gcc/cp/pt.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/auto-fn62.C | 14 |
3 files changed, 26 insertions, 3 deletions
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index ae743c8..e72fdf0 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -5799,10 +5799,15 @@ mark_used (tree decl, tsubst_flags_t complain) actually used until after overload resolution. */ if (BASELINK_P (decl)) { - decl = BASELINK_FUNCTIONS (decl); - if (really_overloaded_fn (decl)) + tree fns = BASELINK_FUNCTIONS (decl); + if (really_overloaded_fn (fns)) return true; - decl = OVL_FIRST (decl); + fns = OVL_FIRST (fns); + if (!mark_used (fns, complain)) + return false; + /* We might have deduced its return type. */ + TREE_TYPE (decl) = TREE_TYPE (fns); + return true; } if (!DECL_P (decl)) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index b45a299..76913cb 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -22643,6 +22643,10 @@ unify_one_argument (tree tparms, tree targs, tree parm, tree arg, return unify_success (explain_p); } + /* Force auto deduction now. Use tf_none to avoid redundant + deprecated warning on deprecated-14.C. */ + mark_single_function (arg, tf_none); + arg_expr = arg; arg = unlowered_expr_type (arg); if (arg == error_mark_node) diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn62.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn62.C new file mode 100644 index 0000000..9c2bff1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn62.C @@ -0,0 +1,14 @@ +// PR c++/105623 +// { dg-do compile { target c++14 } } + +template <class T> +auto g(T fn) { } + +template<typename> +struct base { + static auto value() { } +}; + +struct S : base<void> { + static void f() { g(value); } +}; |