#!/bin/sh set -eu base="${TMPDIR-/tmp}/mcpu-cpp-inhibit-warnings-$$" mkdir -p "$base" trap 'rm -rf "$base"' EXIT HUP INT TERM cat > "$base/directive.c" <<'EOT' #warning requested warning ok EOT # -w suppresses #warning completely. "$MCPU_CPP" --no-config -w "$base/directive.c" \ -o "$base/directive.out" 2>"$base/directive.err" test ! -s "$base/directive.err" grep '^ok$' "$base/directive.out" >/dev/null # -w is a global warning gate, so command-line order relative to -Werror # does not matter and there is no warning left to promote. for options in '-w -Werror' '-Werror -w'; do # shellcheck disable=SC2086 "$MCPU_CPP" --no-config $options "$base/directive.c" \ -o "$base/werror.out" 2>"$base/werror.err" test ! -s "$base/werror.err" done cat > "$base/width.c" <<'EOT' #if 1z24 == 1 ok #endif EOT "$MCPU_CPP" --no-config -w "$base/width.c" \ -o "$base/width.out" 2>"$base/width.err" test ! -s "$base/width.err" grep '^ok$' "$base/width.out" >/dev/null cat > "$base/redefine.c" <<'EOT' #define VALUE 1 #define VALUE 2 VALUE EOT "$MCPU_CPP" --no-config -w "$base/redefine.c" \ -o "$base/redefine.out" 2>"$base/redefine.err" test ! -s "$base/redefine.err" grep '^2$' "$base/redefine.out" >/dev/null cat > "$base/paste.c" <<'EOT' #define BAD(X) X ## + BAD(foo) EOT "$MCPU_CPP" --no-config -w "$base/paste.c" \ -o "$base/paste.out" 2>"$base/paste.err" test ! -s "$base/paste.err" cat > "$base/comments.c" <<'EOT' /* outer /* nested */ // continued \ comment ok EOT # A specific warning class may be enabled, but -w still suppresses its output. # Command-line order does not matter. for options in '-w -Wcomment' '-Wcomment -w' '-w -Wall' '-Wall -w'; do # shellcheck disable=SC2086 "$MCPU_CPP" --no-config $options "$base/comments.c" \ -o "$base/comments.out" 2>"$base/comments.err" test ! -s "$base/comments.err" grep '^ok$' "$base/comments.out" >/dev/null done # Errors are not warnings and must remain visible/fatal under -w. cat > "$base/error.c" <<'EOT' #error requested error EOT if "$MCPU_CPP" --no-config -w "$base/error.c" \ -o "$base/error.out" 2>"$base/error.err"; then echo '-w suppressed a real preprocessing error' >&2 exit 1 fi grep 'error: #error requested error$' "$base/error.err" >/dev/null