Hash :
01b5720b
Author :
Date :
2020-08-11T01:53:13
Use many __attribute__s with clang. * m4/gnulib-common.m4 (_Noreturn): Use __attribute__ __noreturn__ also on clang. * lib/cdefs.h (__glibc_clang_has_attribute, __glibc_clang_has_builtin): New macros. (__THROW, __THROWNL, __NTH, __NTHNL): Use __attribute__ __nothrow__ also on clang. (__warndecl, __warnattr, __errordecl): Use __attribute__ __diagnose_if__ also on older clang versions. (__attribute__): Don't define to empty on clang. (__attribute_malloc__): Use __attribute__ __malloc__ also on clang. (__attribute_pure__): Use __attribute__ __pure__ also on clang. (__attribute_const__): Use __attribute__ __const__ also on clang. (__attribute_used__): Use __attribute__ __used__ also on clang. (__attribute_noinline__): Use __attribute__ __noinline__ also on clang. (__attribute_deprecated__): Use __attribute__ __deprecated__ also on clang. (__attribute_format_arg__): Use __attribute__ __format_arg__ also on clang. (__attribute_format_strfmon__): Use __attribute__ __format__ __strfmon__ also on clang. (__nonnull): Use __attribute__ __nonnull__ also on clang. (__attribute_warn_unused_result__): Use __attribute__ __warn_unused_result__ also on clang. (__always_inline): Use __attribute__ __always_inline__ also on clang. (__attribute_artificial__): Use __attribute__ __artificial__ also on clang >= 7. (__glibc_unlikely, __glibc_likely): Use __builtin_expect also on older clang versions. (_Noreturn): Don't redefine on clang >= 3.5. * lib/arg-nonnull.h (_GL_ARG_NONNULL): Use __attribute__ __nonnull__ also on clang. * lib/dirent.in.h (_GL_ATTRIBUTE_PURE): Use __attribute__ __pure__ also on clang. * lib/stdlib.in.h (_GL_ATTRIBUTE_PURE): Likewise. * lib/string.in.h (_GL_ATTRIBUTE_PURE): Likewise. * lib/wchar.in.h (_GL_ATTRIBUTE_PURE): Likewise. * lib/stdio.in.h (_GL_ATTRIBUTE_FORMAT): Use __attribute__ __format__ also on clang. * lib/monetary.in.h (_GL_ATTRIBUTE_FORMAT): Likewise. * lib/textstyle.in.h (ostream_printf, ostream_vprintf): Likewise. * lib/unitypes.in.h (_UC_ATTRIBUTE_CONST): Use __attribute__ __const__ also on clang. (_UC_ATTRIBUTE_PURE): Use __attribute__ __pure__ also on clang. * lib/noreturn.h (_GL_NORETURN_FUNC, _GL_NORETURN_FUNCPTR): Use __attribute__ __noreturn__ also on clang. * lib/obstack.h (__attribute_noreturn__): Likewise. * lib/file-set.h (record_file): Use __attribute__ __nonnull__ also on clang. * lib/argp-help.c (hol_entry_long_iterate): Use __attribute__ always_inline also on clang. * tests/test-printf-posix.c (func1, func2, func3, func4): Test also on clang.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
/* Macros for declaring functions as non-returning.
Copyright (C) 2017-2020 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Paul Eggert and Bruno Haible. */
#ifndef _NORETURN_H
#define _NORETURN_H 1
/* A "non-returning" function is a function which cannot return normally.
It can transfer control only through longjmp(), throw (in C++), or similar
mechanisms.
This file defines two macros _GL_NORETURN_FUNC and _GL_NORETURN_FUNCPTR,
that declare a function to be non-returning.
_GL_NORETURN_FUNC is for use in function declarations and function
definitions.
_GL_NORETURN_FUNCPTR is for use on function pointers.
Comparison of this file with <stdnoreturn.h>:
<stdnoreturn.h> defines a macro (or keyword) _Noreturn that declares
a function to be non-returning. _Noreturn is only for use in function
declarations and function definitions.
Therefore, if the non-returning functions you have to declare are unlikely
to be accessed through function pointers, and if the efficiency with C++
compilers other than g++, clang, MSVC++ is not an issue to you, you can use
module 'stdnoreturn' instead of this one, and _Noreturn instead of
_GL_NORETURN_FUNC.
*/
/* Declares that a function is nonreturning.
Use in C only code:
_GL_NORETURN_FUNC extern void func (void);
extern _GL_NORETURN_FUNC void func (void);
extern void _GL_NORETURN_FUNC func (void);
Use in C++ only code for a function with C linkage:
extern "C" { _GL_NORETURN_FUNC void func (void); }
Use in C++ only code for a function with C++ linkage:
_GL_NORETURN_FUNC extern void func (void);
Use in C & C++ code for a function with C linkage:
#ifdef __cplusplus
extern "C" {
#endif
_GL_NORETURN_FUNC void func (void);
#ifdef __cplusplus
}
#endif
Use in C & C++ code for a function with current language linkage:
_GL_NORETURN_FUNC extern void func (void);
*/
#if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) \
|| defined __clang__ \
|| (0x5110 <= __SUNPRO_C)
/* For compatibility with _GL_NORETURN_FUNCPTR on clang, use
__attribute__((__noreturn__)), not _Noreturn. */
# define _GL_NORETURN_FUNC __attribute__ ((__noreturn__))
#elif 1200 <= _MSC_VER
/* Use MSVC specific syntax. */
# define _GL_NORETURN_FUNC __declspec (noreturn)
#elif defined __cplusplus
/* Use ISO C++11 syntax when the compiler supports it. */
# if (__cplusplus >= 201103 && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
|| (_MSC_VER >= 1900)
# define _GL_NORETURN_FUNC [[noreturn]]
/* clang++ supports the _Noreturn keyword, but g++ doesn't. */
# elif defined __clang__
# define _GL_NORETURN_FUNC _Noreturn
# else
# define _GL_NORETURN_FUNC /* empty */
# endif
#else
/* Use ISO C11 syntax when the compiler supports it. */
# if __STDC_VERSION__ >= 201112 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
# define _GL_NORETURN_FUNC _Noreturn
# else
# define _GL_NORETURN_FUNC /* empty */
# endif
#endif
/* Declares that a function is nonreturning.
Use in types and declarations that involve function pointers:
_GL_NORETURN_FUNCPTR void (*funcptr) (void);
*/
#if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) \
|| defined __clang__ \
|| (0x5110 <= __SUNPRO_C)
# define _GL_NORETURN_FUNCPTR __attribute__ ((__noreturn__))
#else
# define _GL_NORETURN_FUNCPTR /* empty */
#endif
/* Comments about the compiler dependent language features:
- '_Noreturn' - standardized by ISO C11, available in C only (not in C++),
and not applicable to pointers.
- '[[noreturn]]' - standardized by ISO C++11, available in C++ only,
and not applicable to pointers.
- '__attribute__((__noreturn__))' - available in GCC and clang only,
both in C and C++.
- '__declspec(noreturn)' - available in MSVC only,
both in C and C++, not applicable to pointers.
*/
#endif /* _NORETURN_H */