Blame lib/ignore-value.h

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