c++: Fix demangling of x.operator type
authorJason Merrill <jason@redhat.com>
Sat, 19 Dec 2020 18:10:01 +0000 (13:10 -0500)
committerJason Merrill <jason@redhat.com>
Mon, 21 Dec 2020 20:46:14 +0000 (15:46 -0500)
d_operator_name decides whether "cv" indicates a cast or a conversion
operator based on is_expression.  "on" specifies that we want the conversion
operator.

libiberty/ChangeLog:

* cp-demangle.c (d_unqualified_name): Clear is_expression.
* testsuite/demangle-expected: Add tests.

libiberty/cp-demangle.c
libiberty/testsuite/demangle-expected

index a9f8e759ff533f0e499a784782eed706e1883134..96f43b65ad6cba847a1143fc7cc0449f21da6a22 100644 (file)
@@ -1632,9 +1632,15 @@ d_unqualified_name (struct d_info *di)
     ret = d_source_name (di);
   else if (IS_LOWER (peek))
     {
+      int was_expr = di->is_expression;
       if (peek == 'o' && d_peek_next_char (di) == 'n')
-       d_advance (di, 2);
+       {
+         d_advance (di, 2);
+         /* Treat cv as naming a conversion operator.  */
+         di->is_expression = 0;
+       }
       ret = d_operator_name (di);
+      di->is_expression = was_expr;
       if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR)
        {
          di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2;
index 4ad9da82f2c76f590af2a62e9e6d8c708146b844..6e3e6716defa6551ac34926c15d590fa1a157d25 100644 (file)
@@ -1476,3 +1476,9 @@ void f<int>(decltype (__alignof__(int)))
 
 _Z1fIiEvDTv111__alignof__tlT_EE
 void f<int>(decltype (__alignof__(int{})))
+
+_Z1gI1AEv1SIXadsrT_oncviEE
+void g<A>(S<&A::operator int>)
+
+_Z1jI1AEDTcldtfp_oncvPT_EES1_
+decltype (({parm#1}.(operator A*))()) j<A>(A)