Blame lib/ignore-value.h

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