]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix templated convertion operator demangling
authorNathan Sidwell <nathan@acm.org>
Mon, 12 Jun 2023 23:37:04 +0000 (19:37 -0400)
committerNathan Sidwell <nathan@acm.org>
Tue, 13 Jun 2023 21:07:01 +0000 (17:07 -0400)
Instantiations of templated conversion operators failed to demangle
for cases such as 'operator X<int>', but worked for 'operator X<int>
&', due to thinking the template instantiation of X was the
instantiation of the conversion operator itself.

libiberty/
* cp-demangle.c (d_print_conversion): Remove incorrect
template instantiation handling.
* testsuite/demangle-expected: Add testcases.

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

index 18ab28fd028dcda8abb6d5b62a61f370ec46ba83..3bd303a7544581ac77a7106f64244de9edde0c2e 100644 (file)
@@ -6660,32 +6660,10 @@ d_print_conversion (struct d_print_info *dpi, int options,
       dpt.template_decl = dpi->current_template;
     }
 
-  if (d_left (dc)->type != DEMANGLE_COMPONENT_TEMPLATE)
-    {
-      d_print_comp (dpi, options, d_left (dc));
-      if (dpi->current_template != NULL)
-       dpi->templates = dpt.next;
-    }
-  else
-    {
-      d_print_comp (dpi, options, d_left (d_left (dc)));
-
-      /* For a templated cast operator, we need to remove the template
-        parameters from scope after printing the operator name,
-        so we need to handle the template printing here.  */
-      if (dpi->current_template != NULL)
-       dpi->templates = dpt.next;
+  d_print_comp (dpi, options, d_left (dc));
 
-      if (d_last_char (dpi) == '<')
-       d_append_char (dpi, ' ');
-      d_append_char (dpi, '<');
-      d_print_comp (dpi, options, d_right (d_left (dc)));
-      /* Avoid generating two consecutive '>' characters, to avoid
-        the C++ syntactic ambiguity.  */
-      if (d_last_char (dpi) == '>')
-       d_append_char (dpi, ' ');
-      d_append_char (dpi, '>');
-    }
+  if (dpi->current_template != NULL)
+    dpi->templates = dpt.next;
 }
 
 /* Initialize the information structure we use to pass around
index 52dff883a184f2f5f066cf282946817319c9f6ad..0acd2d635db048a1594ddf0282cc72313593ae9c 100644 (file)
@@ -1662,3 +1662,30 @@ X<int>::F()::{lambda(int)#1}::operator()(int) const
 
 _Z1fIiEv1AIXnxtlT_EEE
 void f<int>(A<noexcept(int{})>)
+
+_ZNO1Ycv1XEv
+Y::operator X() &&
+
+_ZNO1Ycv1XIT_EIvEEv
+Y::operator X<void><void>() &&
+
+_ZNO1Y3bobEv
+Y::bob() &&
+
+_ZNR1Y3bobEv
+Y::bob() &
+
+_ZNKR1YcvRK1XIT_EIvEEv
+Y::operator X<void> const&<void>() const &
+
+_ZZN1XIiEcviEvE1y
+X<int>::operator int()::y
+
+_ZZN1XIiEcv1ZIiEEvE1y
+X<int>::operator Z<int>()::y
+
+_ZZN1Xcv1ZIT_EIiEEvE1y
+X::operator Z<int><int>()::y
+
+_ZZN1XIfEcv1ZIT_EIiEEvE1y
+X<float>::operator Z<int><int>()::y