c++: modules and #pragma diagnostic

To respect the #pragma diagnostic lines in libstdc++ headers when compiling
with module std, we need to represent them in the module.

I think it's reasonable to give serializers direct access to the underlying
data, as here with get_classification_history.  This is a different approach
from how Jakub made PCH streaming members of diagnostic_option_classifier,
but it seems to me that modules handling belongs in module.cc.

libcpp/ChangeLog:

	* line-map.cc (linemap_location_from_module_p): Add.
	* include/line-map.h: Declare it.

gcc/ChangeLog:

	* diagnostic.h (diagnostic_option_classifier): Friend
	diagnostic_context.
	(diagnostic_context::get_classification_history): New.

gcc/cp/ChangeLog:

	* module.cc (module_state::write_diagnostic_classification): New.
	(module_state::write_begin): Call it.
	(module_state::read_diagnostic_classification): New.
	(module_state::read_initial): Call it.
	(dk_string, dump_dc_change): New.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/warn-spec-3_a.C: New test.
	* g++.dg/modules/warn-spec-3_b.C: New test.
	* g++.dg/modules/warn-spec-3_c.C: New test.
This commit is contained in:
Jason Merrill
2024-11-20 16:20:52 +01:00
parent 75ffef5c6f
commit a5933118f3
7 changed files with 240 additions and 1 deletions

View File

@@ -1111,6 +1111,10 @@ extern location_t linemap_module_loc
extern void linemap_module_reparent
(line_maps *, location_t loc, location_t new_parent);
/* TRUE iff the location comes from a module import. */
extern bool linemap_location_from_module_p
(const line_maps *, location_t);
/* Restore the linemap state such that the map at LWM-1 continues.
Return start location of the new map. */
extern location_t linemap_module_restore

View File

@@ -767,6 +767,17 @@ linemap_module_restore (line_maps *set, line_map_uint_t lwm)
return 0;
}
/* TRUE iff the location comes from a module import. */
bool
linemap_location_from_module_p (const line_maps *set, location_t loc)
{
const line_map_ordinary *map = linemap_ordinary_map_lookup (set, loc);
while (map && map->reason != LC_MODULE)
map = linemap_included_from_linemap (set, map);
return !!map;
}
/* Returns TRUE if the line table set tracks token locations across
macro expansion, FALSE otherwise. */