C++ PATCH for c++/70449 (ICE when printing a filename of unknown location)

Manuel López-Ibáñez lopezibanez@gmail.com
Thu Mar 31 01:02:00 GMT 2016


On 30 March 2016 at 23:42, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> On 30/03/16 17:14, Marek Polacek wrote:
>>
>> This test ICEs since the addition of the assert in pp_string which ensures
>> that
>> we aren't trying to print an empty string.  But that's what happens here,
>> the
>> location is actually UNKNOWN_LOCATION, so LOCATION_FILE on that yields
>> null.
>> Fixed byt not trying to print the filename of UNKNOWN_LOCATION.

> Even if we accept the broken location for now (adding some FIXME to the code
> would help the next person to realise this is not normal), if
> LOCATION_FILE() is NULL, we should print "progname" like
> diagnostic_build_prefix() does. Moreover, the filename string should be
> built with file_name_as_prefix() to get correct coloring.

Even better: Use "f ? f : progname" in file_name_as_prefix() and
simplify the code to:

      /* FIXME: Somehow we may get UNKNOWN_LOCATION here: See
g++.dg/cpp0x/constexpr-70449.C */
      const char * prefix = file_name_as_prefix (context,
LOCATION_FILE (location));
        pp_verbatim (context->printer,
                     TREE_CODE (p->decl) == TREE_LIST
                     ? _("%s: In substitution of %qS:\n")
                     : _("%s: In instantiation of %q#D:\n"),
                     prefix, p->decl);
      free (prefix);

Fixes the ICE, adds colors, mentions the broken location and does not
add extra strings.

Cheers,

Manuel.



More information about the Gcc-patches mailing list