On Tue, 19 Jan 2016, Patrick Palka wrote:

On Tue, Jan 19, 2016 at 9:56 AM, Jason Merrill <ja...@redhat.com> wrote:
On 01/18/2016 10:55 PM, Patrick Palka wrote:

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.
@@ -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)))


How does a TEMPLATE_DECL get in here?  Does it have null DECL_LANG_SPECIFIC?

(In the test case auto-fn29.C,) When instantiating the template
function f3,we call tsubst on the CALL_EXPR "f1 (v);".  There, ADL is
performed on the identifier f1 (which is the CALL_EXPR_FN) which
returns the TEMPLATE_DECL f1.  Then mark_used is called on this
CALL_EXPR_FN, only if it's a decl.

If in the test case the call to "f1 (v);" is replaced with "Ape::f1
(v);" then the CALL_EXPR_FN is then an OVERLOAD (to the TEMPLATE_DECL
f1), i.e. not a decl, so we don't call mark_used on it in tsubst.

The DECL_LANG_SPECIFIC of this decl is not null.


I'd think mark_used of a TEMPLATE_DECL should return after setting
TREE_USED, there's nothing else to do with it.

Consider it changed.

Here's the updated patch, with mark_used made to return earlier in case
of a TEMPLATE_DECL.  Also, auto-fn31.C is now consolidated into
auto-fn29.C since the two test cases were so similar.

-- >8 --

gcc/cp/ChangeLog:

        PR c++/69283
        PR c++/67835
        * decl2.c (mark_used): When given a TEMPLATE_DECL, return after
        setting its TREE_USED.

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.
---
 gcc/cp/decl2.c                         |  4 ++++
 gcc/testsuite/g++.dg/cpp1y/auto-fn29.C | 34 ++++++++++++++++++++++++++++++++++
 gcc/testsuite/g++.dg/cpp1y/auto-fn30.C | 21 +++++++++++++++++++++
 3 files changed, 59 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn29.C
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn30.C

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 7d68961..15d7617 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -5068,6 +5068,10 @@ mark_used (tree decl, tsubst_flags_t complain)

   /* Set TREE_USED for the benefit of -Wunused.  */
   TREE_USED (decl) = 1;
+
+  if (TREE_CODE (decl) == TEMPLATE_DECL)
+    return true;
+
   if (DECL_CLONED_FUNCTION_P (decl))
     TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1;

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..f9260e0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn29.C
@@ -0,0 +1,34 @@
+// PR c++/69283
+// { dg-do compile { target c++14 } }
+
+namespace Ape {
+   struct Type {};
+
+   template <typename T>
+   auto f1(T const& v){
+       return true;
+   }
+
+   template <typename T>
+   auto f2(T const& v){
+       return f2(v); // { dg-error "auto" }
+   }
+}
+
+namespace Baboon {
+   template <typename T>
+   bool f3(T const& v){
+       return f1(v);
+   }
+
+   template <typename T>
+   bool f4(T const& v){
+       f2(v);
+   }
+}
+
+int main(){
+   Ape::Type x;
+   Baboon::f3(x);
+   Baboon::f4(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;
+}
--
2.7.0.303.g36d4cae

Reply via email to