blob: 8214d9663b101f03e90024d1781cf1a2274c9609 (
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-warning-control-$$"
mkdir -p "$base"
trap 'rm -rf "$base"' EXIT HUP INT TERM
cat > "$base/comments.c" <<'EOT'
/* outer /* nested */
// continued \
comment
ok
EOT
# Comment warnings are optional and disabled by default.
"$MCPU_CPP" --no-config "$base/comments.c" -o "$base/default.out" 2>"$base/default.err"
test ! -s "$base/default.err"
grep '^ok$' "$base/default.out" >/dev/null
# -Wcomment and -Wcomments are synonyms.
for option in -Wcomment -Wcomments -Wall; do
"$MCPU_CPP" --no-config "$option" "$base/comments.c" \
-o "$base/comment.out" 2>"$base/comment.err"
test "`grep -c 'warning: \"/\*\" within comment' "$base/comment.err"`" -eq 1
test "`grep -c 'warning: multi-line comment' "$base/comment.err"`" -eq 1
done
# A specific -Wno-comment is stronger than the -Wall group regardless of order.
for options in '-Wall -Wno-comment' '-Wno-comment -Wall' \
'-Wall -Wno-comments' '-Wno-comments -Wall'; do
# shellcheck disable=SC2086
"$MCPU_CPP" --no-config $options "$base/comments.c" \
-o "$base/no-comment.out" 2>"$base/no-comment.err"
test ! -s "$base/no-comment.err"
done
# Same-specificity comment options use the last occurrence.
"$MCPU_CPP" --no-config -Wno-comment -Wcomment "$base/comments.c" \
-o "$base/comment-last.out" 2>"$base/comment-last.err"
grep 'warning: multi-line comment' "$base/comment-last.err" >/dev/null
"$MCPU_CPP" --no-config -Wcomment -Wno-comment "$base/comments.c" \
-o "$base/no-comment-last.out" 2>"$base/no-comment-last.err"
test ! -s "$base/no-comment-last.err"
# -Werror does not enable optional comment diagnostics by itself.
"$MCPU_CPP" --no-config -Werror "$base/comments.c" \
-o "$base/werror-only.out" 2>"$base/werror-only.err"
test ! -s "$base/werror-only.err"
# When comment diagnostics are enabled, -Werror promotes them to errors.
if "$MCPU_CPP" --no-config -Wcomment -Werror "$base/comments.c" \
-o "$base/comment-error.out" 2>"$base/comment-error.err"; then
echo '-Wcomment -Werror did not fail' >&2
exit 1
fi
grep 'error: "/\*" within comment' "$base/comment-error.err" >/dev/null
# -Werror/-Wno-error have equal specificity; the last occurrence wins.
cat > "$base/directive.c" <<'EOT'
#warning requested warning
ok
EOT
"$MCPU_CPP" --no-config -Werror -Wno-error "$base/directive.c" \
-o "$base/no-error.out" 2>"$base/no-error.err"
grep 'warning: #warning requested warning$' "$base/no-error.err" >/dev/null
if "$MCPU_CPP" --no-config -Wno-error -Werror "$base/directive.c" \
-o "$base/error-last.out" 2>"$base/error-last.err"; then
echo '-Wno-error -Werror did not fail' >&2
exit 1
fi
grep 'error: #warning requested warning$' "$base/error-last.err" >/dev/null
# Existing always-issued warnings are also promoted by -Werror.
cat > "$base/width.c" <<'EOT'
#if 1z24 == 1
ok
#endif
EOT
if "$MCPU_CPP" --no-config -Werror "$base/width.c" \
-o "$base/width.out" 2>"$base/width.err"; then
echo 'zNNN warning was not promoted by -Werror' >&2
exit 1
fi
grep 'error: invalid zNNN integer-width suffix; suffix ignored$' "$base/width.err" >/dev/null
cat > "$base/redefine.c" <<'EOT'
#define VALUE 1
#define VALUE 2
EOT
if "$MCPU_CPP" --no-config -Werror "$base/redefine.c" \
-o "$base/redefine.out" 2>"$base/redefine.err"; then
echo 'macro redefinition warning was not promoted by -Werror' >&2
exit 1
fi
grep "error: macro 'VALUE' redefined$" "$base/redefine.err" >/dev/null
cat > "$base/paste.c" <<'EOT'
#define BAD(X) X ## +
BAD(foo)
EOT
if "$MCPU_CPP" --no-config -Werror "$base/paste.c" \
-o "$base/paste.out" 2>"$base/paste.err"; then
echo 'invalid paste warning was not promoted by -Werror' >&2
exit 1
fi
grep 'error: pasting "foo" and "+" does not give a valid preprocessing token$' \
"$base/paste.err" >/dev/null
|