On 3/12/26 9:51 AM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
OK.
-- >8 -- Diagnostic classification changes via _Pragma can occur in macros, but weren't taking effect in imported modules. The issue is that we were reading the diagnostic classification map before we processed the macro maps, which meant that all locations in macros were just falling back to the abstract location of the module itself. Fixed by moving the processing after we've read the macro maps. PR c++/124459 gcc/cp/ChangeLog: * module.cc (module_state::read_initial): Move read_diagnostic_classification after read_macro_maps. gcc/testsuite/ChangeLog: * g++.dg/modules/warn-spec-4_a.C: New test. * g++.dg/modules/warn-spec-4_b.C: New test. Signed-off-by: Nathaniel Shead <[email protected]> --- gcc/cp/module.cc | 10 ++++++---- gcc/testsuite/g++.dg/modules/warn-spec-4_a.C | 15 +++++++++++++++ gcc/testsuite/g++.dg/modules/warn-spec-4_b.C | 8 ++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/warn-spec-4_a.C create mode 100644 gcc/testsuite/g++.dg/modules/warn-spec-4_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 8c79c248ec7..4580b287116 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -21206,10 +21206,6 @@ module_state::read_initial (cpp_reader *reader) else if (!read_ordinary_maps (config.ordinary_locs, config.loc_range_bits)) ok = false;- if (ok && have_locs && config.ordinary_locs- && !read_diagnostic_classification (global_dc)) - ok = false; - /* Allocate the REMAP vector. */ slurp->alloc_remap (config.num_imports);@@ -21270,6 +21266,12 @@ module_state::read_initial (cpp_reader *reader)else if (!read_macro_maps (config.macro_locs)) ok = false;+ /* Diagnostic classification streaming needs to come after reading+ macro maps to handle _Pragmas in macros. */ + if (ok && have_locs && config.ordinary_locs + && !read_diagnostic_classification (global_dc)) + ok = false; + /* Note whether there's an active initializer. */ active_init_p = !is_header () && bool (config.active_init);diff --git a/gcc/testsuite/g++.dg/modules/warn-spec-4_a.C b/gcc/testsuite/g++.dg/modules/warn-spec-4_a.Cnew file mode 100644 index 00000000000..2eddc1b4c56 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/warn-spec-4_a.C @@ -0,0 +1,15 @@ +// PR c++/124459 +// { dg-additional-options "-fmodules -Wunused-but-set-variable" } +// Test diagnostic pragmas in macro maps. + +export module M; + +#define MACRO(t) \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"") \ + int x = t; \ + _Pragma("GCC diagnostic pop") + +export template <typename T> void foo(T t) { + MACRO(t); +} diff --git a/gcc/testsuite/g++.dg/modules/warn-spec-4_b.C b/gcc/testsuite/g++.dg/modules/warn-spec-4_b.C new file mode 100644 index 00000000000..fce9b849308 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/warn-spec-4_b.C @@ -0,0 +1,8 @@ +// PR c++/124459 +// { dg-additional-options "-fmodules -Wunused-but-set-variable" } + +import M; + +void test() { + foo(123); +}
