[C++ PATCH] Don't ICE if __decltype is called on CALL_EXPR with type dependent CALL_EXPR_FN (PR c++/37540)

Jakub Jelinek jakub@redhat.com
Tue Oct 21 17:56:00 GMT 2008


Hi!

The recently added code to finish_decltype_type looks at CALL_EXPR_FN's
type, but as can be seen on the testcase below, if expr (the CALL_EXPR)
isn't type dependent (result type is known), CALL_EXPR_FN can still
be type dependent, can have NULL result type etc.

This patch handles that case the same as if the whole expr is type
dependent.  Alternatively patch could do:
-   if (type_dependent_expression_p (expr))
+   if (type_dependent_expression_p (expr)
+       || (TREE_CODE (expr) == CALL_EXPR
+	    && type_dependent_expression_p (CALL_EXPR_FN (expr))))

Ok for trunk if bootstrap/regtest passes?

2008-10-21  Jakub Jelinek  <jakub@redhat.com>

	PR c++/37540
	* semantics.c (finish_decltype_type): If CALL_EXPR_FN is
	type dependent, do the same as if expr is type dependent.

	* g++.dg/cpp0x/decltype13.C: New test.

--- gcc/cp/semantics.c.jj	2008-10-14 10:17:49.000000000 +0200
+++ gcc/cp/semantics.c	2008-10-21 17:58:54.000000000 +0200
@@ -4496,6 +4496,7 @@ finish_decltype_type (tree expr, bool id
 
   if (type_dependent_expression_p (expr))
     {
+    is_dependent_expr:
       type = cxx_make_type (DECLTYPE_TYPE);
       DECLTYPE_TYPE_EXPR (type) = expr;
       DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
@@ -4609,7 +4610,9 @@ finish_decltype_type (tree expr, bool id
           tree fndecl = get_callee_fndecl (expr);
           if (fndecl && fndecl != error_mark_node)
             type = TREE_TYPE (TREE_TYPE (fndecl));
-          else 
+	  else if (type_dependent_expression_p (CALL_EXPR_FN (expr)))
+	    goto is_dependent_expr;
+	  else
             {
               tree target_type = TREE_TYPE (CALL_EXPR_FN (expr));
               if ((TREE_CODE (target_type) == REFERENCE_TYPE
--- gcc/testsuite/g++.dg/cpp0x/decltype13.C.jj	2008-10-21 18:01:40.000000000 +0200
+++ gcc/testsuite/g++.dg/cpp0x/decltype13.C	2008-10-21 18:00:58.000000000 +0200
@@ -0,0 +1,13 @@
+// PR c++/37540
+// { dg-do compile }
+
+struct A
+{
+  int g () { return 0; }
+};
+
+template <typename T> void
+f (A a)
+{
+  __decltype (a.g ()) i;
+}

	Jakub



More information about the Gcc-patches mailing list