[patch c++]: Fix PR/47211 - ICE: in cp_build_addr_expr_1, at cp/typeck.c:4866 with -fms-extensions

Kai Tietz ktietz70@googlemail.com
Fri Jan 7 14:50:00 GMT 2011


Hello,

this patch addresses issue reported at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47211

2011-01-07  Kai Tietz

	PR c++/47211
	* decl.c (build_ptrmem_type): Resolve VAR_DECL
	and FUNCTION_DECL to their underlying type.
	* typeck.c (cp_build_addr_expr_1): Handle flag_ms_extensions.

2011-01-07  Kai Tietz

	PR c++/47211
	* g++.dg/ext/pr47211.C: New.


Tested for x86_64-w64-mingw32, and i686-pc-cygwin. I am not sure if
this ...DECL handling should be done in build_ptrmem_type itself, or
if we should handle it just in typeck.c's cp_build_addr_expr_1.

Ok?

Regards,
Kai
-------------- next part --------------
Index: gcc/gcc/cp/decl.c
===================================================================
--- gcc.orig/gcc/cp/decl.c	2011-01-07 15:21:47.000000000 +0100
+++ gcc/gcc/cp/decl.c	2011-01-07 14:48:03.354579300 +0100
@@ -7423,6 +7423,9 @@ build_ptrmemfunc_type (tree type)
 tree
 build_ptrmem_type (tree class_type, tree member_type)
 {
+  if (TREE_CODE (class_type) == FUNCTION_DECL
+      || TREE_CODE (class_type) == VAR_DECL)
+    class_type = TREE_TYPE (class_type);
   if (TREE_CODE (member_type) == METHOD_TYPE)
     {
       cp_cv_quals quals = type_memfn_quals (member_type);
Index: gcc/gcc/cp/typeck.c
===================================================================
--- gcc.orig/gcc/cp/typeck.c	2011-01-07 15:23:34.000000000 +0100
+++ gcc/gcc/cp/typeck.c	2011-01-07 15:18:12.580785500 +0100
@@ -4859,11 +4859,12 @@ cp_build_addr_expr_1 (tree arg, bool str
     offset_ref:
       /* Turn a reference to a non-static data member into a
 	 pointer-to-member.  */
+
       {
 	tree type;
 	tree t;
 
-	gcc_assert (PTRMEM_OK_P (arg));
+	gcc_assert (PTRMEM_OK_P (arg) || flag_ms_extensions);
 
 	t = TREE_OPERAND (arg, 1);
 	if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
@@ -4878,7 +4879,7 @@ cp_build_addr_expr_1 (tree arg, bool str
 	t = make_ptrmem_cst (type, TREE_OPERAND (arg, 1));
 	return t;
       }
-
+      /* Fall through.  */
     default:
       break;
     }
Index: gcc/gcc/testsuite/g++.dg/ext/pr47211.C
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/gcc/testsuite/g++.dg/ext/pr47211.C	2011-01-07 15:29:44.492606100 +0100
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fms-extensions" } */
+
+class chile
+{
+  typedef void (chile::* pmf) ();
+  void bar (pmf pmethod)
+  {
+    &(this->*pmethod);
+  }
+};
+
+


More information about the Gcc-patches mailing list