c++: Abbreviated function template return type [PR92187]
authorPatrick Palka <ppalka@redhat.com>
Sat, 18 Apr 2020 10:22:14 +0000 (06:22 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sat, 18 Apr 2020 10:22:14 +0000 (06:22 -0400)
When updating an auto return type of an abbreviated function template in
splice_late_return_type, we should also propagate PLACEHOLDER_TYPE_CONSTRAINTS
(and cv-qualifiers) of the original auto node.

gcc/cp/ChangeLog:

PR c++/92187
* pt.c (splice_late_return_type): Propagate cv-qualifiers and
PLACEHOLDER_TYPE_CONSTRAINTS from the original auto node to the new one.

gcc/testsuite/ChangeLog:

PR c++/92187
* g++.dg/concepts/abbrev5.C: New test.
* g++.dg/concepts/abbrev6.C: New test.

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/concepts/abbrev5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/concepts/abbrev6.C [new file with mode: 0644]

index b89b6d88fd3bda5886366d5daf489edec8232245..45c422f59507e167ea2534a744b3ad0b805dae9d 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-18  Patrick Palka  <ppalka@redhat.com>
+
+       PR c++/92187
+       * pt.c (splice_late_return_type): Propagate cv-qualifiers and
+       PLACEHOLDER_TYPE_CONSTRAINTS from the original auto node to the new one.
+
 2020-04-17  Patrick Palka  <ppalka@redhat.com>
 
        PR c++/94483
index 0a8ec3198d2373fcd2f3ba22e9a064d7b665dd66..9e39f46a090c602b52628f89fd30f0388779571a 100644 (file)
@@ -29032,10 +29032,17 @@ splice_late_return_type (tree type, tree late_return_type)
     {
       tree idx = get_template_parm_index (*auto_node);
       if (TEMPLATE_PARM_LEVEL (idx) <= processing_template_decl)
-       /* In an abbreviated function template we didn't know we were dealing
-          with a function template when we saw the auto return type, so update
-          it to have the correct level.  */
-       *auto_node = make_auto_1 (TYPE_IDENTIFIER (*auto_node), true);
+       {
+         /* In an abbreviated function template we didn't know we were dealing
+            with a function template when we saw the auto return type, so update
+            it to have the correct level.  */
+         tree new_auto = make_auto_1 (TYPE_IDENTIFIER (*auto_node), false);
+         PLACEHOLDER_TYPE_CONSTRAINTS (new_auto)
+           = PLACEHOLDER_TYPE_CONSTRAINTS (*auto_node);
+         TYPE_CANONICAL (new_auto) = canonical_type_parameter (new_auto);
+         new_auto = cp_build_qualified_type (new_auto, TYPE_QUALS (*auto_node));
+         *auto_node = new_auto;
+       }
     }
   return type;
 }
index e5d0d92344ce8713d2fb23fb48fd9f0a2512fdb5..08bef53e9112e5d1d960cd9be60eafafc41e494a 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-18  Patrick Palka  <ppalka@redhat.com>
+
+       PR c++/92187
+       * g++.dg/concepts/abbrev5.C: New test.
+       * g++.dg/concepts/abbrev6.C: New test.
+
 2020-04-17  Jeff Law  <law@redhat.com>
 
        PR rtl-optimization/90275
diff --git a/gcc/testsuite/g++.dg/concepts/abbrev5.C b/gcc/testsuite/g++.dg/concepts/abbrev5.C
new file mode 100644 (file)
index 0000000..de594b5
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/92187
+// { dg-do compile { target concepts } }
+
+template <typename>
+concept C = false;
+
+C auto f(auto)
+{
+  return 42; // { dg-error "deduced return type" }
+}
+
+void foo()
+{
+  f(0);
+}
diff --git a/gcc/testsuite/g++.dg/concepts/abbrev6.C b/gcc/testsuite/g++.dg/concepts/abbrev6.C
new file mode 100644 (file)
index 0000000..862675e
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-do compile { target concepts } }
+
+const auto &f(auto)
+{
+  static int n;
+  return n;
+}
+
+void foo()
+{
+  f(5) = 0; // { dg-error "read-only" }
+}