mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
c++/modules: Support diagnostic classification changes in macros [PR124459]
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 <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
@@ -21217,10 +21217,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);
|
||||
|
||||
@@ -21281,6 +21277,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);
|
||||
|
||||
|
||||
15
gcc/testsuite/g++.dg/modules/warn-spec-4_a.C
Normal file
15
gcc/testsuite/g++.dg/modules/warn-spec-4_a.C
Normal file
@@ -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);
|
||||
}
|
||||
8
gcc/testsuite/g++.dg/modules/warn-spec-4_b.C
Normal file
8
gcc/testsuite/g++.dg/modules/warn-spec-4_b.C
Normal file
@@ -0,0 +1,8 @@
|
||||
// PR c++/124459
|
||||
// { dg-additional-options "-fmodules -Wunused-but-set-variable" }
|
||||
|
||||
import M;
|
||||
|
||||
void test() {
|
||||
foo(123);
|
||||
}
|
||||
Reference in New Issue
Block a user