https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79106
Bug ID: 79106
Summary: wrong source line printed in diagnostics for a
translation unit
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
When printing the source file line in diagnostic messages for a translation
unit (a .i or .ii file) GCC uses the source file the translation unit was
created from rather than the translation unit itself. That can be pretty
confusing for those unaware of this "feature." (It took me a few minutes to
figure out what was going on while reducing a large translation unit to a small
test case.)
$ (set -x && cat a.c && cat a.i && /build/gcc-5-branch/gcc/xgcc -B
/build/gcc-5-branch/gcc -S a.i)
+ cat a.c
int foo (void) {
return -1;
}
+ cat a.i
# 1 "a.c"
int foo (void) {
return "";
}
+ /build/gcc-5-branch/gcc/xgcc -B /build/gcc-5-branch/gcc -S a.i
a.c: In function ‘foo’:
a.c:2:10: warning: return makes integer from pointer without a cast
[-Wint-conversion]
return -1;
^
Clang, in contrast, prints the contents of translation unit as one would
presumably expect as I do:
$ clang -S a.i
a.c:2:10: warning: incompatible pointer to integer conversion returning
'char [1]' from a function with result type 'int' [-Wint-conversion]
return "";
^~
1 warning generated.