different behaviors on gcc warning between one-step compile and separate-step compile

Wx L lwxiang1994@gmail.com
Mon May 20 03:07:00 GMT 2019


hi, I used gcc5.5.0(configure only with --prefix), glibc2.17 to compile
some code with *conversion-null *warning in it.
it is every simple so I put it here:

#include <stdio.h>
int main()
{
return NULL;
}

*What I Got*
I did compile with:
g++ -Wall -S test.c
as expected, here came out the warning "warning: converting to non-pointer
type 'int' from NULL [-Wconversion-null]"

then I did compile step by step:
g++ -Wall -E test.c
g++ -Wall -S test.i

the warning just disappeared, nothing came out.

*What I have Tried*
I tried to figure out if all warning will be disabled, so I compile some
code with different warning in it, just *conversion-null *will be disabled
when separate-step compiling.
I tried to figure out if all gcc version behave the same way, and I found
gcc5.5.0,gcc7.1.0,gcc7.3.0 did, but gcc4.8.5 works when separate-step
compiling.
After comparing the preprocessing files(*.i) from gcc4.8.5 and gcc5.5.0, I
found that gcc5.5.0 put some linemarkers in it while gcc4.8.5 don't.
here is the line markers:

int main()
{
        int a =
# 4 "a.c" 3 4
               __null
# 4 "a.c"
                   ;
 return a;
}

if I do preprocess with gcc4.8.5, and do compile with gcc5.5.0, it warns
well.
if I do preprocess with gcc5.5.0, and do compile with gcc4.8.5, it can not
warn *conversion-null.*
if I do preprocess with gcc5.5.0 and add -P option(remove linemarkers), and
do compile with gcc5.5.0, it warns well.

Now I am sure that it is the linemarkers added by gcc5.5.0 preprocessor
that cause the *conversion-null *warning not work as expected.
But why one-step compile works? So I add -save-temps to one-step compile to
see if it got a different preprocessing file.
just like:

g++ -Wall -save-temps -S test.c

and now it can not warns too! the preprocessing file is exactly same as the
one with "g++ -Wall -E test.c"

*What Help I Need*
After all the test, I confuse that if there is a bug with warning analyzer
when analyzing the *conversion-null *warning code which around by
linemarkers?

Is that -P a workaround to solve this problem when separate-step compiling?
Will -P leads to some other problems?



More information about the Gcc-help mailing list