Patchwork C++ PATCH for c++/49003 (DR 1207, use of 'this' in trailing return type)

login
register
mail settings
Submitter Jason Merrill
Date July 4, 2011, 9:40 p.m.
Message ID <4E123365.6010406@redhat.com>
Download mbox | patch
Permalink /patch/103171/
State New
Headers show

Comments

Jason Merrill - July 4, 2011, 9:40 p.m.
On 06/29/2011 05:15 PM, Jason Merrill wrote:
> This patch adds support for use of 'this' (implicitly or explicitly) in
> the trailing-return-type of a member function.

The above patch wasn't enough, though.  The following patch fixes some 
issues that arose with real uses, including mangling.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit acbc60694bf95f13f9088ed4d5b3d18780aaf754
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jul 4 10:44:29 2011 -0400

    	* cp-demangle.c (d_expression): Handle 'this'.
    	(d_print_comp) [DEMANGLE_COMPONENT_FUNCTION_PARAM]: Likewise.

diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index f136322..29badbb 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -2738,10 +2738,18 @@  d_expression (struct d_info *di)
       /* Function parameter used in a late-specified return type.  */
       int index;
       d_advance (di, 2);
-      index = d_compact_number (di);
-      if (index < 0)
-	return NULL;
-
+      if (d_peek_char (di) == 'T')
+	{
+	  /* 'this' parameter.  */
+	  d_advance (di, 1);
+	  index = 0;
+	}
+      else
+	{
+	  index = d_compact_number (di) + 1;
+	  if (index == 0)
+	    return NULL;
+	}
       return d_make_function_param (di, index);
     }
   else if (IS_DIGIT (peek)
@@ -4400,9 +4408,17 @@  d_print_comp (struct d_print_info *dpi, int options,
       return;
 
     case DEMANGLE_COMPONENT_FUNCTION_PARAM:
-      d_append_string (dpi, "{parm#");
-      d_append_num (dpi, dc->u.s_number.number + 1);
-      d_append_char (dpi, '}');
+      {
+	long num = dc->u.s_number.number;
+	if (num == 0)
+	  d_append_string (dpi, "this");
+	else
+	  {
+	    d_append_string (dpi, "{parm#");
+	    d_append_num (dpi, num);
+	    d_append_char (dpi, '}');
+	  }
+      }
       return;
 
     case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index 4980cf1..2dc74be 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -3905,6 +3905,10 @@  decltype ({parm#1}+{parm#2}) add<int, double>(int, double)
 --format=gnu-v3
 _Z4add3IidEDTclL_Z1gEfp_fp0_EET_T0_
 decltype (g({parm#1}, {parm#2})) add3<int, double>(int, double)
+# 'this' test
+--format=gnu-v3
+_ZN1A1fIiEEDTcldtdtdefpT1b1fIT_EEEv
+decltype ((((*this).b).(f<int>))()) A::f<int>()
 # new (2008) built in types test
 --format=gnu-v3
 _Z1fDfDdDeDhDsDi