compilers won't produce the same result (for instance diagnostics warnings)
when compiling preprocessed source code.
+
-An alternative to *run_second_cpp* is to use *-fdirectives-only* (for GCC) or
-*-frewrite-includes* (for Clang). This will cause the compiler to leave the
-macros and other preprocessor information, and only process the *#include*
-directives. When run in this way, the preprocessor arguments will be passed
-to the compiler since it still has to do _some_ preprocessing (like macros).
+A solution to the above mentioned downside is to set *run_second_cpp* to false
+and pass *-fdirectives-only* (for GCC) or *-frewrite-includes* (for Clang) to
+the compiler. This will cause the compiler to leave the macros and other
+preprocessor information, and only process the *#include* directives. When run
+in this way, the preprocessor arguments will be passed to the compiler since it
+still has to do _some_ preprocessing (like macros).
*sloppiness* (*CCACHE_SLOPPINESS*)::
if (conf->run_second_cpp) {
args_extend(*compiler_args, cpp_args);
} else if (found_directives_only || found_rewrite_includes) {
- // Need to pass the macros and any other preprocessor directives again
+ // Need to pass the macros and any other preprocessor directives again.
args_extend(*compiler_args, cpp_args);
if (found_directives_only) {
args_add(cpp_args, "-fdirectives-only");
- // The preprocessed source code still needs some more preprocessing
+ // The preprocessed source code still needs some more preprocessing.
args_add(*compiler_args, "-fpreprocessed");
args_add(*compiler_args, "-fdirectives-only");
}
if (found_rewrite_includes) {
args_add(cpp_args, "-frewrite-includes");
- // The preprocessed source code still needs some more preprocessing
+ // The preprocessed source code still needs some more preprocessing.
args_add(*compiler_args, "-x");
args_add(*compiler_args, actual_language);
}
SUITE_cpp1_PROBE() {
touch test.c
if $COMPILER_TYPE_GCC; then
- if ! $UNCACHED_COMPILE -E -fdirectives-only test.c >/dev/null 2>&1; then
+ if ! $UNCACHED_COMPILE -E -fdirectives-only test.c >&/dev/null; then
echo "-fdirectives-only not supported by compiler"
return
fi
elif $COMPILER_TYPE_CLANG; then
- if ! $UNCACHED_COMPILE -E -frewrite-includes test.c >/dev/null 2>&1; then
+ if ! $UNCACHED_COMPILE -E -frewrite-includes test.c >&/dev/null; then
echo "-frewrite-includes not supported by compiler"
return
fi
export CCACHE_NOCPP2=1
echo "#define FOO 1" >test1.h
backdate test1.h
- echo "#include \"test1.h\"" >test1.c
- echo "#define BAR 2" >>test1.c
- echo "int foo(int x) { return FOO; }" >>test1.c
- echo "int bar(int x) { return BAR; }" >>test1.c
- echo "int baz(int x) { return BAZ; }" >>test1.c
+ echo '#include "test1.h"' >test1.c
+ echo '#define BAR 2' >>test1.c
+ echo 'int foo(int x) { return FOO; }' >>test1.c
+ echo 'int bar(int x) { return BAR; }' >>test1.c
+ echo 'int baz(int x) { return BAZ; }' >>test1.c
}
SUITE_cpp1() {
elif $COMPILER_TYPE_CLANG; then
cpp_flag="-frewrite-includes"
fi
- cpp_flag="$cpp_flag -DBAZ=3"
+ cpp_flag+=" -DBAZ=3"
# -------------------------------------------------------------------------
TEST "Base case"