]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/81236 - auto variable and auto function
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 15 Mar 2018 03:08:24 +0000 (03:08 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 15 Mar 2018 03:08:24 +0000 (03:08 +0000)
* pt.c (tsubst_baselink): Update the type of the BASELINK after
mark_used.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258547 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1y/auto-fn48.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/auto-fn49.C [new file with mode: 0644]

index a4ffc663dc1aaddf81f9db9879bafa094af8e321..fc124b440bba7d90bced78663efc22bd0f6113fb 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/81236 - auto variable and auto function
+       * pt.c (tsubst_baselink): Update the type of the BASELINK after
+       mark_used.
+
 2018-03-14  Jason Merrill  <jason@redhat.com>
 
        PR c++/83916 - ICE with template template parameters.
index 14321816cdecd073e6828951f165fb9fa894f040..2ea5fc79a2c124536ef3f766c690a0384d16484f 100644 (file)
@@ -14700,9 +14700,16 @@ tsubst_baselink (tree baselink, tree object_type,
   /* If lookup found a single function, mark it as used at this point.
      (If lookup found multiple functions the one selected later by
      overload resolution will be marked as used at that point.)  */
-  if (!template_id_p && !really_overloaded_fn (fns)
-      && !mark_used (OVL_FIRST (fns), complain) && !(complain & tf_error))
-    return error_mark_node;
+  if (!template_id_p && !really_overloaded_fn (fns))
+    {
+      tree fn = OVL_FIRST (fns);
+      bool ok = mark_used (fn, complain);
+      if (!ok && !(complain & tf_error))
+       return error_mark_node;
+      if (ok && BASELINK_P (baselink))
+       /* We might have instantiated an auto function.  */
+       TREE_TYPE (baselink) = TREE_TYPE (fn);
+    }
 
   if (BASELINK_P (baselink))
     {
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn48.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn48.C
new file mode 100644 (file)
index 0000000..bf9448e
--- /dev/null
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++14 } }
+
+template <class T> struct A
+{
+  static auto fn() { }
+  static void f()
+  {
+    auto x = fn;
+  }
+};
+
+int main()
+{
+  A<int>::f();
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn49.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn49.C
new file mode 100644 (file)
index 0000000..d2e4906
--- /dev/null
@@ -0,0 +1,12 @@
+// CWG issue 2335
+// { dg-do compile { target c++14 } }
+
+template <class... Ts> struct partition_indices {
+  static auto compute_right () {}
+  static constexpr auto right = compute_right;
+};
+auto foo () -> partition_indices<>;
+void f() {
+  auto x = foo();
+  auto y = x.right;
+}