[cfe-dev] Warnings are different on preprocessed file

Richtarsky, Martin martin.richtarsky at sap.com
Wed Mar 12 07:13:59 PDT 2014


Hi,

is this expected behavior?

cat preproc_warning.sh
#!/bin/bash

echo "-- direct compilation:"
clang++ -c preproc_warning.cpp -o /dev/null
echo "-- preprocessing:"
clang++ -E preproc_warning.cpp -o preproc_out.cpp
echo "-- compilation of preprocessed source:"
clang++ -c preproc_out.cpp -o /dev/null


cat preproc_warning.cpp
#include <stddef.h>

#define CHECK(a) ( a ? 1 : NULL)

int func1()
{
    int a;
    return NULL; // produces warning during direct compilation and compilation of preprocessed source
}

int func2()
{
    int a;
    return (CHECK(a)); // produces warning only on preprocessed source
}


shows this output:
-- direct compilation:
preproc_warning.cpp:8:12: warning: implicit conversion of NULL constant to 'int' [-Wnull-conversion]
    return NULL; // produces warning during direct compilation and compilation of preprocessed source
    ~~~~~~ ^~~~
           0
1 warning generated.
-- preprocessing:
-- compilation of preprocessed source:
preproc_warning.cpp:8:12: warning: implicit conversion of NULL constant to 'int' [-Wnull-conversion]
    return __null;
    ~~~~~~ ^~~~~~
           0
preproc_warning.cpp:14:23: warning: implicit conversion of NULL constant to 'int' [-Wnull-conversion]
    return (( a ? 1 : __null));
    ~~~~~~            ^~~~~~
                      0
2 warnings generated.


Best regards,
Martin




More information about the cfe-dev mailing list