This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

How it can be UNKNOWN_LOCATION? It has to be somewhere in the input file!

This is what Clang prints:

prog.cc:5:3: warning: type definition in a constexpr function is a C++14 extension [-Wc++14-extensions]
  enum E { a = f<0> () };
  ^

This is what we print:

In instantiation of 'constexpr int f() [with int <anonymous> = 0]':
prog.cc:5:22:   required from here
cc1plus: error: body of constexpr function 'constexpr int f() [with int <anonymous> = 0]' not a return-statement

This is very broken: The fact that input_location is UNKNOWN_LOCATION makes us print "cc1plus" in the error.

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.

Something like:

      const char *filename = LOCATION_FILE (location);
/* FIXME: Somehow we may get UNKNOWN_LOCATION here: See g++.dg/cpp0x/constexpr-70449.C */
      if (filename == NULL) filename = progname;
      const char * prefix = file_name_as_prefix (context, filename);

	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);

The above also avoids adding yet another slightly different new string for translation.

Cheers,

Manuel.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]