https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61321

            Bug ID: 61321
           Summary: demangler crash on casts in template parameters
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: palves at redhat dot com

The fix for bug 59195 (C++ demangler handles conversion operator incorrectly)
makes the demangler crash crash due to infinite recursion, in case of casts in
template parameters.  For example:

 template<int> struct A {};
 template <typename Y> void function_temp(A<sizeof ((Y)(999))>) {}
 template void function_temp<int>(A<sizeof (int)>);

The function_temp<int> instantiation  mangles to:
  _Z13function_tempIiEv1AIXszcvT_Li999EEE

The demangler parses this as:

typed name
  template
    name 'function_temp'
    template argument list
      builtin type int
  function type
    builtin type void
    argument list
      template
        name 'A'
        template argument list
          unary operator
            operator sizeof 
            unary operator
              cast
                template parameter 0
              literal
                builtin type int
                name '999'

And after this patch, when printing the template argument list of A (what
should be "<sizeof (int)>"), the template parameter 0 (that is, "T_") now
refers to the first parameter of the the template argument list of the 'A'
template, exactly what we were trying to print, while it should actually refer
to the first parameter of the 'function_temp' template.  This leads to infinite
recursion, and stack exaustion.

(This is particularly nasty for GDB, as it causes an immediate crash at
startup.)

Reply via email to