diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 4665a29a24d896b5da518892c04a4a8897b8c861..88f283bc4bd898a493ba019986d4043f20ad4c7c 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -8140,6 +8140,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, d_init = build_x_compound_expr_from_list (d_init, ELK_INIT, tf_warning_or_error); d_init = resolve_nondeduced_context (d_init, tf_warning_or_error); + /* Force auto deduction now. Use tf_none to avoid redundant warnings + on deprecated-14.C. */ + mark_single_function (d_init, tf_none); } enum auto_deduction_context adc = adc_variable_type; if (DECL_DECOMPOSITION_P (decl)) diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn65.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn65.C new file mode 100644 index 0000000000000000000000000000000000000000..78bb004303bd7655d833b0e3e330ad7d8e71f587 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn65.C @@ -0,0 +1,10 @@ +// PR c++/106893 +// { dg-do compile { target c++14 } } + +template <typename T> +struct CoordTraits +{ + static auto GetX(T const &p) { return 1; } +}; +typedef CoordTraits<int> Traits; +static constexpr auto GetX = Traits::GetX;