Any flag on clang like gcc -fpreprocessed

at Preprocessor Options (Using the GNU Compiler Collection (GCC)) we can find a flag

-fpreprocessed
Indicate to the preprocessor that the input file has already been preprocessed. This suppresses things like macro expansion, trigraph conversion, escaped newline splicing, and processing of most directives. The preprocessor still recognizes and removes comments, so that you can pass a file preprocessed with -C to the compiler without problems. In this mode the integrated preprocessor is little more than a tokenizer for the front ends.

-fpreprocessed is implicit if the input file has one of the extensions ‘.i’, ‘.ii’ or ‘.mi’. These are the extensions that GCC uses for preprocessed files created by -save-temps.

any flag on clang have the same behavior: “just want run preprocessor -E and do not check the macro”

for example

//////example.cpp
#include "1.h"
#if TEST_MACRO == 2
#else
#error "unsupport TEST_MACRO"
#endif
  • when use command: gcc -w -x c -fpreprocessed -dD -E
    we can get preprocessor
  • when use command: clang -w -x c -dD -E
    will get error like:

#error "unsupport TEST_MACRO"

so any flag on clang can do the same things

1 Like

Can someone warm-hearted answer this question

We don’t seem to have -fpreprocessed; but instead of -x c you could try -x cpp-output (which says to treat the input files as if they were “.i” files).

-x c same do not take the same effect,

the problem handle c type file, not ‘-i’ files

The suggestion was to use -x cpp-output, but it doesn’t work for this use case.

A warning message will result if not suppressed (like with the -w in the original post):

previously preprocessed input

That is, Clang doesn’t like to perform preprocessor-related operations on already-preprocessed input. I think that is sensible.

ok, Thank you for your patience and help