c++: auto member function and auto variable [PR106893]
authorJason Merrill <jason@redhat.com>
Mon, 12 Sep 2022 17:47:34 +0000 (13:47 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 12 Sep 2022 19:46:59 +0000 (15:46 -0400)
As with PR105623, we need to call mark_single_function sooner to
resolve the type of a BASELINK.

PR c++/106893
PR c++/90451

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Call mark_single_function.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/auto-fn65.C: New test.

gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp1y/auto-fn65.C [new file with mode: 0644]

index 4665a29..88f283b 100644 (file)
@@ -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 (file)
index 0000000..78bb004
--- /dev/null
@@ -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;