https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102887
Bug ID: 102887 Summary: wrong warning location with macro expansion Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- As noted here: https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582316.html in a -Wuninitialized warning for the use of a variable in the expansion of a macro the warning points to the macro definition and not to the point of its expansion as in other warnings such as -Warray-bounds. The test case below shows the difference. Pointing also to the point of the macro's expansion is important in large functions. $ cat t.C && gcc -O2 -S -Wall -Wextra t.C #define X(x) x ? x + 1 : 2 // warning here (not helpful) int f (int i, int j) { int x; // note here (good) if (i < 0) x = i + 1; if (j < 0) return X (x); return -1; } #define A(i) a[i] // note here (good) extern int a[4]; // note here (good) int g (int i) { if (i < 0) return A (7); // warning here (helpful) return -1; } t.C: In function ‘int f(int, int)’: t.C:1:16: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized] 1 | #define X(x) x ? x + 1 : 2 // warning here (not helpful) | ^ t.C:5:7: note: ‘x’ was declared here 5 | int x; // note here (good) | ^ t.C: In function ‘int g(int)’: t.C:13:17: warning: array subscript 7 is above array bounds of ‘int [4]’ [-Warray-bounds] 13 | #define A(i) a[i] // note here (good) | ~~~^ t.C:19:12: note: in expansion of macro ‘A’ 19 | return A (7); // warning here (helpful) | ^ t.C:14:12: note: while referencing ‘a’ 14 | extern int a[4]; // note here (good) | ^