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

login
register
mail settings
Submitter Kai Tietz
Date Jan. 8, 2011, 2:41 p.m.
Message ID <AANLkTiknVTW+OZpQa5KhpumwqRVcZLdyHGLUguisX0Jy@mail.gmail.com>
Download mbox | patch
Permalink /patch/77953/
State New
Headers show

Comments

Kai Tietz - Jan. 8, 2011, 2:41 p.m.
2011/1/8 Paolo Carlini <pcarlini@gmail.com>:
> ... watch trailing blank lines... ;)
>
> Paolo
>

Well, this is caused by copy&paste. corrected. thanks

Kai

Patch

Index: gcc/gcc/cp/typeck.c
===================================================================
--- gcc.orig/gcc/cp/typeck.c	2011-01-08 15:39:31.899135600 +0100
+++ gcc/gcc/cp/typeck.c	2011-01-08 15:39:47.528310200 +0100
@@ -4558,7 +4558,14 @@  build_x_unary_op (enum tree_code code, t
 
       /* A pointer to member-function can be formed only by saying
 	 &X::mf.  */
-      if (!flag_ms_extensions && TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
+      if (flag_ms_extensions && TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
+          && !PTRMEM_OK_P (xarg) && TREE_CODE (xarg) == OFFSET_REF)
+	{
+	  if (TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
+	      && TYPE_P (TREE_OPERAND (xarg, 0)))
+	    PTRMEM_OK_P (xarg) = 1;
+	}
+      if (TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
 	  && (TREE_CODE (xarg) != OFFSET_REF || !PTRMEM_OK_P (xarg)))
 	{
 	  if (TREE_CODE (xarg) != OFFSET_REF
@@ -4863,8 +4870,6 @@  cp_build_addr_expr_1 (tree arg, bool str
 	tree type;
 	tree t;
 
-	gcc_assert (PTRMEM_OK_P (arg));
-
 	t = TREE_OPERAND (arg, 1);
 	if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
 	  {
@@ -4873,6 +4878,8 @@  cp_build_addr_expr_1 (tree arg, bool str
 	    return error_mark_node;
 	  }
 
+	gcc_assert (PTRMEM_OK_P (arg));
+
 	type = build_ptrmem_type (context_for_name_lookup (t),
 				  TREE_TYPE (t));
 	t = make_ptrmem_cst (type, TREE_OPERAND (arg, 1));
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-08 15:40:00.769067500 +0100
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fms-extensions" } */
+
+class chile
+{
+  typedef void (chile::* pmf) ();
+  void bar (pmf pmethod)
+  {
+    &(this->*pmethod); // { dg-error "invalid use of" }
+  }
+  void doo(void) { }
+  pmf foo(pmf pmethod) { return &(chile::doo); }
+};