[PATCH] Handle REINTERPRET_CAST_EXPR in cp_walk_tree (PR c++/38795)

Jakub Jelinek jakub@redhat.com
Tue Jan 13 12:39:00 GMT 2009


Hi!

This testcase ICEs because check_for_bare_parameter_packs, which calls
cp_walk_tree, doesn't discover the bare parameter pack in reinterpret_cast.
If a normal cast is used instead, cp_walk_tree finds them.

The difference is that cp_walk_subtrees handles CAST_EXPR by walking
the type and the argument, but for other *_CAST_EXPR doesn't do anything
special, so the type isn't walked at all.

Fixed by handling *_CAST_EXPR the same way as CAST_EXPR.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2009-01-13  Jakub Jelinek  <jakub@redhat.com>

	PR c++/38795
	* tree.c (cp_walk_subtrees): Handle REINTERPRET_CAST_EXPR,
	STATIC_CAST_EXPR, CONST_CAST_EXPR and DYNAMIC_CAST_EXPR the same
	as CAST_EXPR.

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

--- gcc/cp/tree.c.jj	2008-12-19 10:19:10.000000000 +0100
+++ gcc/cp/tree.c	2009-01-13 09:58:25.000000000 +0100
@@ -1,6 +1,6 @@
 /* Language-dependent node constructors for parse phase of GNU compiler.
    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Hacked by Michael Tiemann (tiemann@cygnus.com)
 
@@ -2441,6 +2441,10 @@ cp_walk_subtrees (tree *tp, int *walk_su
       break;
 
     case CAST_EXPR:
+    case REINTERPRET_CAST_EXPR:
+    case STATIC_CAST_EXPR:
+    case CONST_CAST_EXPR:
+    case DYNAMIC_CAST_EXPR:
       if (TREE_TYPE (*tp))
 	WALK_SUBTREE (TREE_TYPE (*tp));
 
--- gcc/testsuite/g++.dg/cpp0x/pr38795.C.jj	2009-01-13 10:02:06.000000000 +0100
+++ gcc/testsuite/g++.dg/cpp0x/pr38795.C	2009-01-13 10:01:46.000000000 +0100
@@ -0,0 +1,13 @@
+// PR c++/38795
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+template<typename... T> int foo(int i)
+{
+  return *reinterpret_cast<T*>(i);	// { dg-error "not expanded with|T" }
+}
+
+void bar(int i)
+{
+  foo<int>(i);
+}

	Jakub



More information about the Gcc-patches mailing list