blob: 339d098834e66fd95bbad7a5770f99bbe8e99434 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!/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
|