re PR c++/37540 (ICE on __decltype of method call in function template)
authorJason Merrill <jason@gcc.gnu.org>
Thu, 20 Nov 2008 18:40:52 +0000 (13:40 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 20 Nov 2008 18:40:52 +0000 (13:40 -0500)
        PR c++/37540
        * call.c (build_over_call): Take the address of the function even
        in a template.
        (build_new_method_call): Remember the type of the called function
        in a template.

From-SVN: r142054

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/decltype14.C [new file with mode: 0644]

index fe2eab6..558682b 100644 (file)
@@ -1,3 +1,11 @@
+2008-11-20  Jason Merrill  <jason@redhat.com>
+
+       PR c++/37540
+       * call.c (build_over_call): Take the address of the function even
+       in a template.
+       (build_new_method_call): Remember the type of the called function
+       in a template.
+
 2008-11-19  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/37142
@@ -8,7 +16,7 @@
 
        PR c++/35405
        * pt.c (lookup_template_class): Check pointers before dereferencing
-         Them.
+       them.
        * error.c (dump_template_decl): Likewise.
 
 2008-11-19  Jason Merrill  <jason@redhat.com>
index af3fd99..bbd6a22 100644 (file)
@@ -5103,7 +5103,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
       tree expr;
       tree return_type;
       return_type = TREE_TYPE (TREE_TYPE (fn));
-      expr = build_call_list (return_type, fn, args);
+      expr = build_call_list (return_type, build_addr_func (fn), args);
       if (TREE_THIS_VOLATILE (fn) && cfun)
        current_function_returns_abnormally = 1;
       if (!VOID_TYPE_P (return_type))
@@ -5964,10 +5964,16 @@ build_new_method_call (tree instance, tree fns, tree args,
     }
 
   if (processing_template_decl && call != error_mark_node)
-    call = (build_min_non_dep_call_list
-           (call,
-            build_min_nt (COMPONENT_REF, orig_instance, orig_fns, NULL_TREE),
-            orig_args));
+    {
+      if (TREE_CODE (call) == INDIRECT_REF)
+       call = TREE_OPERAND (call, 0);
+      call = (build_min_non_dep_call_list
+             (call,
+              build_min (COMPONENT_REF, TREE_TYPE (CALL_EXPR_FN (call)),
+                         orig_instance, orig_fns, NULL_TREE),
+              orig_args));
+      call = convert_from_reference (call);
+    }
 
  /* Free all the conversions we allocated.  */
   obstack_free (&conversion_obstack, p);
index 569accd..43454d2 100644 (file)
@@ -1,3 +1,8 @@
+2008-11-20  Jason Merrill  <jason@redhat.com>
+
+       PR c++/37540
+       * g++.dg/cpp0x/decltype14.C: New test.
+
 2008-11-20  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/37868
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype14.C b/gcc/testsuite/g++.dg/cpp0x/decltype14.C
new file mode 100644 (file)
index 0000000..9484173
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/37540
+
+struct A
+{
+  int g() {return 0;}
+};
+
+template <typename T_> 
+void f(A a)
+{
+  __decltype(a.g()) i;
+}
+
+int main()
+{
+  f<int>(A());
+}