ignore-value: Fix self-test.
[gnulib.git] / tests / test-ignore-value.c
1 /* Test the "ignore-value" module.
2
3    Copyright (C) 2011 Free Software Foundation, Inc.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 /* Written by Eric Blake.  */
19
20 #include <config.h>
21
22 #include "ignore-value.h"
23
24 #include <stdio.h>
25 #include <sys/types.h>
26
27 #ifndef ATTRIBUTE_RETURN_CHECK
28 # if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
29 #  define ATTRIBUTE_RETURN_CHECK
30 # else
31 #  define ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
32 # endif
33 #endif
34
35 struct s { int i; };
36 static char doChar (void) ATTRIBUTE_RETURN_CHECK;
37 static int doInt (void) ATTRIBUTE_RETURN_CHECK;
38 static off_t doOff (void) ATTRIBUTE_RETURN_CHECK;
39 static void *doPtr (void) ATTRIBUTE_RETURN_CHECK;
40 static struct s doStruct (void) ATTRIBUTE_RETURN_CHECK;
41
42 static char
43 doChar (void)
44 {
45   return 0;
46 }
47
48 static int
49 doInt (void)
50 {
51   return 0;
52 }
53
54 static off_t
55 doOff (void)
56 {
57   return 0;
58 }
59
60 static void *
61 doPtr (void)
62 {
63   return NULL;
64 }
65
66 static struct s
67 doStruct (void)
68 {
69   static struct s s1;
70   return s1;
71 }
72
73 int
74 main (void)
75 {
76   /* If this test can compile with -Werror and the same warnings as
77      the rest of the project, then we are properly silencing warnings
78      about ignored return values.  */
79   ignore_value (doChar ());
80   ignore_value (doInt ());
81   ignore_value (doOff ());
82   ignore_value (doPtr ());
83   ignore_value (doStruct ());
84   return 0;
85 }