On Fri, 2015-12-04 at 12:09 +0100, Bernd Schmidt wrote: > On 12/03/2015 09:33 PM, David Malcolm wrote: > > The attached patch updates the handling of %q+D, simplifying > > the implementation, and ensuring that it retains the range > > information of the decl, giving: > > > > diagnostic-ranges-1.c:6:7: warning: unused variable ‘redundant’ > > [-Wunused-variable] > > int redundant; > > ^~~~~~~~~ > > For most of it I've convinced myself that it looks OK.
Thanks. > > void > > -rich_location::set_range (unsigned int idx, source_range src_range, > > - bool show_caret_p, bool overwrite_loc_p) > > +rich_location::set_range (line_maps *set, unsigned int idx, > > + source_location loc, bool show_caret_p) > > { > > Here you need to update the function comment. Is the attached suitable? > This is a bit of a strange function. As far as I can tell, it's called > from only two places, one in c-common.c (which overwrites idx 0, i.e. > the entire range, and therefore is uninteresting), idx 0 is the primary location associated with the rich_location; but I'm not sure it's strictly correct to say "the entire range". In theory there could be other locations/ranges within the rich_location e.g. if someone did something like: rich_location richloc (loc_A); /* primary loc is "loc_A" */ /* ...then add a couple of other ranges of interest e.g. to print a bogus infix binary operator, or somesuch. */ richloc.add_range (range_B); richloc.add_range (range_C); /* richloc now has: idx == 0 (primary) at loc_A idx == 1 at range_B idx == 2 at range_C. */ /* emit it... */ error_at_richloc (&richloc, "something bad involving %q+D", decl); where the %q+D leads to the idx == 0 location being overwritten by DECL_SOURCE_LOCATION (decl) instead of loc_A. > and one in > text_info::set_location. I wonder about the use of "idx" in the latter. > As far as I can tell, that's used by the Fortran frontend to keep track > of two separate ranges for their diagnostics - correct? Yes. These format codes that manipulate the location of the diagnostic were one of the big surprises to me when I was writing this. This function exists to support them. > Is that really > related to the normal function of rich_location and how it keeps track > of multiple ranges, Yes. > or would that be better expressed by keeping two > rich_locations in text_info? No; keeping track of multiple locations/ranges, potentially with multiple carets is rich_location's job. Hope this makes sense; does it look OK with the proposed comment fix? Dave
diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 333e835..0c8f328 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -2064,14 +2064,14 @@ rich_location::add_range (location_range *src_range) m_ranges[m_num_ranges++] = *src_range; } -/* Add or overwrite the range given by IDX. It must either - overwrite an existing range, or add one *exactly* on the end of +/* Add or overwrite the location given by IDX. It must either + overwrite an existing location, or add one *exactly* on the end of the array. This is primarily for use by gcc when implementing diagnostic format decoders e.g. the "+" in the C/C++ frontends, for handling format codes like "%q+D" (which writes the source location of a - tree back into range 0 of the rich_location). + tree back into location 0 of the rich_location). If SHOW_CARET_P is true, then the range should be rendered with a caret at its starting location. This