diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-05-01 18:12:12 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-05-03 13:49:20 -0700 |
commit | c08f85d74f2964c00613930342bfa27f971fc2be (patch) | |
tree | 23fcb7481abab5e59a9d62e7aae2d73a7d2f0b8f /lib/attribute.h | |
parent | 2ac33b29fc09f72a18eb08829eb142eb86428747 (diff) | |
download | gnulib-c08f85d74f2964c00613930342bfa27f971fc2be.tar.gz |
attribute: new module
This simplifies use of GCC and C2X attributes like ‘deprecated’.
* MODULES.html.sh: Add attribute.
* doc/attribute.texi, lib/attribute.h, modules/attribute: New files.
* doc/gnulib.texi (Particular Modules): Add Attributes.
* lib/backupfile.c, lib/fnmatch.c, lib/freopen-safer.c:
* lib/mbrtoc32.c, lib/mbrtowc.c, lib/nstrftime.c, lib/quotearg.c:
* lib/savewd.c, lib/unistr/u8-uctomb-aux.c, lib/unistr/u8-uctomb.c:
* lib/vasnprintf.c:
Include attribute.h, and let it define FALLTHROUGH.
* lib/bitset/base.h, lib/c-stack.c (__attribute__): Remove macro.
* lib/bitset/base.h (ATTRIBUTE_UNUSED): Define in terms of
_GL_ATTRIBUTE_MAYBE_UNUSED, for forwards compatibility to C2X.
* lib/dfa.c (FALLTHROUGH): Define consistently with gl_COMMON_BODY.
This is a copy since Gawk doesn’t use Gnulib.
* lib/di-set.h (_GL_ATTRIBUTE_NONNULL): Remove definition that
is incompatible with gl_COMMON_BODY’s. All uses changed.
* lib/fts.c: Include attribte.h, for FALLTHROUGH.
Keep the existing FALLTHROUGH definition since Glibc might use it,
and it does no harm to Gnulib’s FALLTHROUGH.
* lib/fts_.h, lib/inttostr.h:
(__GNUC_PREREQ): Remove; no longer needed.
(__attribute_warn_unused_result__): Remove. All uses
replaced by _GL_ATTRIBUTE_NODISCARD.
* lib/gl_list.h, lib/gl_map.h, lib/gl_omap.h, lib/gl_oset.h:
* lib/gl_set.h: Prefer _GL_ATTRIBUTE_NODISCARD to an ifdeffed
__attribute__ ((__warn_unused_result__)), for forward
compatibility to C2X.
* lib/hash.h (_GL_ATTRIBUTE_WUR): Remove. All uses replaced by
_GL_ATTRIBUTE_NODISCARD.
(_GL_ATTRIBUTE_DEPRECATED): Remove, since gl_COMMON_BODY defines it.
* lib/ino-map.h (_GL_ATTRIBUTE_NONNULL): Remove. All uses
replaced by gl_COMMON_BODY’s implementation, which has a
slightly different signature.
* lib/safe-alloc.h (_GL_ATTRIBUTE_RETURN_CHECK):
Remove. All uses replaced by _GL_ATTRIBUTE_NODISCARD.
* lib/unused-parameter.h (_GL_UNUSED_PARAMETER):
Define in terms of _GL_ATTRIBUTE_MAYBE_UNUSED.
No doubt all uses should be replaced, at some point.
* m4/gnulib-common.m4 (_GL_GNUC_PREREQ): New macro.
(_Noreturn): Use it.
(_GL_HAS_ATTRIBUTE, _GL_ATTRIBUTE_ALLOC_SIZE)
(_GL_ATTRIBUTE_ALWAYS_INLINE, _GL_ATTRIBUTE_ARTIFICIAL)
(_GL_ATTRIBUTE_COLD)
(_GL_ATTRIBUTE_DEPRECATED, _GL_ATTRIBUTE_ERROR)
(_GL_ATTRIBUTE_WARNING, _GL_ATTRIBUTE_EXTERNALLY_VISIBLE)
(_GL_ATTRIBUTE_FALLTHROUGH, _GL_ATTRIBUTE_FORMAT)
(_GL_ATTRIBUTE_LEAF, _GL_ATTRIBUTE_MAY_ALIAS)
(_GL_ATTRIBUTE_MAYBE_UNUSED)
(_GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOINLINE)
(_GL_ATTRIBUTE_NONNULL, _GL_ATTRIBUTE_NONSTRING)
(_GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED, _GL_ATTRIBUTE_PURE)
(_GL_ATTRIBUTE_SENTINEL): New macros.
* modules/backup-rename, modules/backupfile, modules/c-vasnprintf:
* modules/fnmatch, modules/freopen-safer, modules/fts:
* modules/mbrtoc32, modules/mbrtowc, modules/nstrftime:
* modules/quotearg, modules/savewd:
* modules/unistdio/u16-u16-vasnprintf:
* modules/unistdio/u16-vasnprintf:
* modules/unistdio/u32-u32-vasnprintf:
* modules/unistdio/u32-vasnprintf:
* modules/unistdio/u8-u8-vasnprintf:
* modules/unistdio/u8-vasnprintf:
* modules/unistdio/ulc-vasnprintf:
* modules/unistr/u8-uctomb, modules/vasnprintf:
(Depends-on:): Add attribute module.
Diffstat (limited to 'lib/attribute.h')
-rw-r--r-- | lib/attribute.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/attribute.h b/lib/attribute.h new file mode 100644 index 0000000000..ffd9bdfa28 --- /dev/null +++ b/lib/attribute.h @@ -0,0 +1,56 @@ +/* ATTRIBUTE_* macros for using attributes in GCC and similar compilers + + Copyright 2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +/* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_* + macros used within Gnulib. */ + +#ifndef _GL_ATTRIBUTE_H +#define _GL_ATTRIBUTE_H + +/* C2X standard attributes have macro names that do not begin with + 'ATTRIBUTE_'. */ +#define DEPRECATED _GL_ATTRIBUTE_DEPRECATED +#define FALLTHROUGH _GL_ATTRIBUTE_FALLTHROUGH +#define MAYBE_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED +#define NODISCARD _GL_ATTRIBUTE_NODISCARD + +/* Attributes from GCC have macro names beginning with 'ATTRIBUTE_' to + avoid name clashes. */ +#define ATTRIBUTE_ALLOC_SIZE(args) _GL_ATTRIBUTE_ALLOC_SIZE(args) +#define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE +#define ATTRIBUTE_ARTIFICIAL _GL_ATTRIBUTE_ARTIFICIAL +#define ATTRIBUTE_COLD _GL_ATTRIBUTE_COLD +#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST +#define ATTRIBUTE_DEPRECATED _GL_ATTRIBUTE_DEPRECATED +#define ATTRIBUTE_ERROR(msg) _GL_ATTRIBUTE_ERROR(msg) +#define ATTRIBUTE_EXTERNALLY_VISIBLE _GL_ATTRIBUTE_EXTERNALLY_VISIBLE +#define ATTRIBUTE_FORMAT(spec) _GL_ATTRIBUTE_FORMAT(spec) +#define ATTRIBUTE_LEAF _GL_ATTRIBUTE_LEAF +#define ATTRIBUTE_MAY_ALIAS _GL_ATTRIBUTE_MAY_ALIAS +#define ATTRIBUTE_MALLOC _GL_ATTRIBUTE_MALLOC +#define ATTRIBUTE_NOINLINE _GL_ATTRIBUTE_NOINLINE +#define ATTRIBUTE_NONNULL(args) _GL_ATTRIBUTE_NONNULL(args) +#define ATTRIBUTE_NONSTRING _GL_ATTRIBUTE_NONSTRING +#define ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_NOTHROW +#define ATTRIBUTE_PACKED _GL_ATTRIBUTE_PACKED +#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE +#define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL(pos) +#define ATTRIBUTE_WARNING(msg) _GL_ATTRIBUTE_WARNING(msg) + +#endif /* _GL_ATTRIBUTE_H */ |