1 /* $NetBSD: gccw.c,v 1.2 2022/10/08 16:12:50 christos Exp $ */
2
3 /*
4 * This is a regression test for all the things that gcc is meant to warn
5 * about.
6 *
7 * gcc version 3 breaks several tests:
8 *
9 * -W does not report missing return value
10 *
11 * -Wunused does not report unused parameter
12 */
13
14 #include <stdio.h>
15 #include <setjmp.h>
16
17 jmp_buf jbuf;
18
19 /* -Wmissing-prototypes: no previous prototype for 'test1' */
20 /* -Wimplicit: return type defaults to `int' */
test1(void)21 test1(void)
22 {
23 /* -Wunused: unused variable `foo' */
24 int foo;
25
26 /* -Wparentheses: suggest parentheses around && within || */
27 printf("%d\n", 1 && 2 || 3 && 4);
28 /* -W: statement with no effect */
29 0;
30 /* BROKEN in gcc 3 */
31 /* -W: control reaches end of non-void function */
32 }
33
34
35 /* -W??????: unused parameter `foo' */
test2(int foo)36 void test2(int foo)
37 {
38 enum {
39 a = 10, b = 15} moe;
40 int bar;
41
42 /* -Wuninitialized: 'bar' might be used uninitialized in this function */
43 /* -Wformat: format argument is not a pointer (arg 2) */
44 printf("%s\n", bar);
45 /* -Wformat: too few arguments for format */
46 printf("%s%s\n", "bar");
47 /* -Wformat: too many arguments for format */
48 printf("%s\n", "bar", "bar");
49
50 /* -Wswitch: enumeration value `b' not handled in switch */
51 switch (moe) {
52 case a:
53 return;
54 }
55 }
56
57 /* -Wstrict-prototypes: function declaration isn't a prototype */
test3()58 void test3()
59 {
60 }
61