C++: Fix ICE during mangling of conversion operator function template
Resolves an ICE in C++ mangling for conversion operator function templates.
This commit fixes an Internal Compiler Error (ICE) that occurred during the mangling of C++ conversion operator function templates. The problem arose because the FNDECL_USED_AUTO macro expected a FUNCTION_DECL but was sometimes given a TEMPLATE_DECL. The fix involves using STRIP_TEMPLATE earlier in the mangling process to ensure that the macro operates on the correct declaration type, thus preventing the crash and enabling proper mangling of these constructs.
In Details
The write_reflection function in mangle.cc was encountering an ICE when processing TEMPLATE_DECLs for conversion operator function templates because FNDECL_USED_AUTO requires a FUNCTION_DECL. This commit modifies write_reflection to call STRIP_TEMPLATE on its argument before passing it to write_unqualified_name. This ensures that the inner declaration is used, resolving the ICE by always providing a FUNCTION_DECL or equivalent to FNDECL_USED_AUTO when appropriate.
- Mangling
- The process of encoding type information and other details into a function or variable name. This allows C++ to support features like function overloading and namespaces by creating unique names for entities that would otherwise have the same base name.
- ICE
- Internal Compiler Error. A condition where the compiler encounters an unrecoverable error during its execution, leading to a crash. This typically indicates a bug within the compiler itself.
- Conversion operator
- A special member function in C++ that allows an object of a class to be implicitly converted to another type. For example,
operator int()would allow an object to be converted to an integer. - Function template
- A blueprint for creating functions in C++. The compiler can generate specific function instances from a template based on the types of arguments provided.
- STRIP_TEMPLATE
- A macro or utility function within GCC that, when applied to a declaration, returns the underlying declaration after removing any template wrappers. This is used to access the non-template part of a templated entity.
- mangle.cc
- A source file in GCC responsible for implementing the name mangling scheme for C++ entities.