mark_used is wrongly diagnosing a use of a TEMPLATE_DECL (e.g. the call
to f1 in function f3 of auto-fn29.C below) for having an undeduced
'auto' return type.  This doesn't make sense, because an 'auto' used
inside a template doesn't get deduced until after the template is
instantiated.  So for a TEMPLATE_DECL we shouldn't diagnose a use of
undeduced 'auto' here.  After instantiation, presumably we will call
mark_used on the resulting FUNCTION_DECL which will check for undeduced
auto appropriately.

Bootstrapped and regtested on x86_64-pc-linux-gnu, no new regressions.
Is this OK to commit?

gcc/cp/ChangeLog:

        PR c++/69283
        PR c++/67835
        * decl2.c (mark_used): Don't complain about an undeduced 'auto'
        in a TEMPLATE_DECL.

gcc/testsuite/ChangeLog:

        PR c++/69283
        PR c++/67835
        * g++.dg/cpp1y/auto-fn29.C: New test.
        * g++.dg/cpp1y/auto-fn30.C: New test.
        * g++.dg/cpp1y/auto-fn31.C: New test.
---
 gcc/cp/decl2.c                         |  4 +++-
 gcc/testsuite/g++.dg/cpp1y/auto-fn29.C | 23 +++++++++++++++++++++++
 gcc/testsuite/g++.dg/cpp1y/auto-fn30.C | 21 +++++++++++++++++++++
 gcc/testsuite/g++.dg/cpp1y/auto-fn31.C | 22 ++++++++++++++++++++++
 4 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn29.C
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn30.C
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn31.C

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index a7212ca0..849375f 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -5112,7 +5112,9 @@ mark_used (tree decl, tsubst_flags_t complain)
       || DECL_LANG_SPECIFIC (decl) == NULL
       || DECL_THUNK_P (decl))
     {
-      if (!processing_template_decl && type_uses_auto (TREE_TYPE (decl)))
+      if (!processing_template_decl
+         && TREE_CODE (decl) != TEMPLATE_DECL
+         && type_uses_auto (TREE_TYPE (decl)))
        {
          if (complain & tf_error)
            error ("use of %qD before deduction of %<auto%>", decl);
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn29.C 
b/gcc/testsuite/g++.dg/cpp1y/auto-fn29.C
new file mode 100644
index 0000000..cd10460
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn29.C
@@ -0,0 +1,23 @@
+// PR c++/69283
+// { dg-do compile { target c++14 } }
+
+namespace Ape {
+   struct Type {};
+
+   template <typename T>
+   auto f1(T const& v){
+       return true;
+   }
+}
+
+namespace Baboon {
+   template <typename T>
+   bool f3(T const& v){
+       return f1(v);
+   }
+}
+
+int main(){
+   Ape::Type x;
+   Baboon::f3(x);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn30.C 
b/gcc/testsuite/g++.dg/cpp1y/auto-fn30.C
new file mode 100644
index 0000000..e005e6e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn30.C
@@ -0,0 +1,21 @@
+// PR c++/67835
+// { dg-do compile { target c++14 } }
+
+template<class Tag, class T>
+auto g(Tag tag, T x) {
+ return f(tag, x);
+}
+
+namespace abc {
+struct tag {};
+
+struct A {};
+
+template<class T>
+auto f(tag, T x) { return x; }
+}
+
+int main() {
+ g(abc::tag(), abc::A());
+ return 0;
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn31.C 
b/gcc/testsuite/g++.dg/cpp1y/auto-fn31.C
new file mode 100644
index 0000000..7849632
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn31.C
@@ -0,0 +1,22 @@
+// { dg-do compile { target c++14 } }
+
+namespace Ape {
+   struct Type {};
+
+   template <typename T>
+   auto f1(T const& v){
+        return f1(v); // { dg-error "auto" }
+   }
+}
+
+namespace Baboon {
+   template <typename T>
+   void f3(T const& v){
+       f1(v);
+   }
+}
+
+int main(){
+   Ape::Type x;
+   Baboon::f3(x);
+}
-- 
2.7.0.83.gdfccd77.dirty

Reply via email to