Blame gl/tests/ignore-value.h

Packit aea12f
/* ignore a function return without a compiler warning.  -*- coding: utf-8 -*-
Packit aea12f
Packit aea12f
   Copyright (C) 2008-2019 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   This program is free software: you can redistribute it and/or modify
Packit aea12f
   it under the terms of the GNU General Public License as published by
Packit aea12f
   the Free Software Foundation; either version 3 of the License, or
Packit aea12f
   (at your option) any later version.
Packit aea12f
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
   GNU General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU General Public License
Packit aea12f
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
/* Written by Jim Meyering, Eric Blake and Pádraig Brady.  */
Packit aea12f
Packit aea12f
/* Use "ignore_value" to avoid a warning when using a function declared with
Packit aea12f
   gcc's warn_unused_result attribute, but for which you really do want to
Packit aea12f
   ignore the result.  Traditionally, people have used a "(void)" cast to
Packit aea12f
   indicate that a function's return value is deliberately unused.  However,
Packit aea12f
   if the function is declared with __attribute__((warn_unused_result)),
Packit aea12f
   gcc issues a warning even with the cast.
Packit aea12f
Packit aea12f
   Caution: most of the time, you really should heed gcc's warning, and
Packit aea12f
   check the return value.  However, in those exceptional cases in which
Packit aea12f
   you're sure you know what you're doing, use this function.
Packit aea12f
Packit aea12f
   For the record, here's one of the ignorable warnings:
Packit aea12f
   "copy.c:233: warning: ignoring return value of 'fchown',
Packit aea12f
   declared with attribute warn_unused_result".  */
Packit aea12f
Packit aea12f
#ifndef _GL_IGNORE_VALUE_H
Packit aea12f
#define _GL_IGNORE_VALUE_H
Packit aea12f
Packit aea12f
/* Normally casting an expression to void discards its value, but GCC
Packit aea12f
   versions 3.4 and newer have __attribute__ ((__warn_unused_result__))
Packit aea12f
   which may cause unwanted diagnostics in that case.  Use __typeof__
Packit aea12f
   and __extension__ to work around the problem, if the workaround is
Packit aea12f
   known to be needed.  */
Packit aea12f
#if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
Packit aea12f
# define ignore_value(x) \
Packit aea12f
    (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
Packit aea12f
#else
Packit aea12f
# define ignore_value(x) ((void) (x))
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#endif