Blame lib/ignore-value.h

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