Prefer c++11-style [[attr]] syntax over __attribute__ (attr)

Where Clang and GCC both support __attribute__ (attr) and
GCC supports [[gnu::attr]], Clang promises it will support
[[gnu::attr]]
This commit is contained in:
Aaron Gyes 2019-02-10 04:20:01 -08:00
parent e461858964
commit 34fa8ef2d2
4 changed files with 16 additions and 18 deletions

View File

@ -151,7 +151,7 @@ long convert_hex_digit(wchar_t d) {
#ifdef HAVE_BACKTRACE_SYMBOLS
// This function produces a stack backtrace with demangled function & method names. It is based on
// https://gist.github.com/fmela/591333 but adapted to the style of the fish project.
static const wcstring_list_t __attribute__((noinline))
[[gnu::noinline]] static const wcstring_list_t
demangled_backtrace(int max_frames, int skip_levels) {
void *callstack[128];
const int n_max_frames = sizeof(callstack) / sizeof(callstack[0]);
@ -182,8 +182,7 @@ demangled_backtrace(int max_frames, int skip_levels) {
return backtrace_text;
}
void __attribute__((noinline))
show_stackframe(const wchar_t msg_level, int frame_count, int skip_levels) {
[[gnu::noinline]] void show_stackframe(const wchar_t msg_level, int frame_count, int skip_levels) {
if (frame_count < 1) return;
// TODO: Decide if this is still needed. I'm commenting it out because it caused me some grief
@ -202,7 +201,7 @@ show_stackframe(const wchar_t msg_level, int frame_count, int skip_levels) {
#else // HAVE_BACKTRACE_SYMBOLS
void __attribute__((noinline)) show_stackframe(const wchar_t msg_level, int, int) {
[[gnu::noinline]] void show_stackframe(const wchar_t msg_level, int, int) {
debug_shared(msg_level, L"Sorry, but your system does not support backtraces");
}
#endif // HAVE_BACKTRACE_SYMBOLS
@ -622,7 +621,7 @@ static void debug_shared(const wchar_t level, const wcstring &msg) {
}
static const wchar_t level_char[] = {L'E', L'W', L'2', L'3', L'4', L'5'};
void __attribute__((noinline)) debug_impl(int level, const wchar_t *msg, ...) {
[[gnu::noinline]] void debug_impl(int level, const wchar_t *msg, ...) {
int errno_old = errno;
va_list va;
va_start(va, msg);
@ -636,7 +635,7 @@ void __attribute__((noinline)) debug_impl(int level, const wchar_t *msg, ...) {
errno = errno_old;
}
void __attribute__((noinline)) debug_impl(int level, const char *msg, ...) {
[[gnu::noinline]] void debug_impl(int level, const char *msg, ...) {
if (!should_debug(level)) return;
int errno_old = errno;
char local_msg[512];
@ -2041,7 +2040,7 @@ int create_directory(const wcstring &d) {
return ok ? 0 : -1;
}
__attribute__((noinline)) void bugreport() {
[[gnu::noinline]] void bugreport() {
debug(0, _(L"This is a bug. Break on 'bugreport' to debug."));
debug(0, _(L"If you can reproduce it, please report: %s."), PACKAGE_BUGREPORT);
}
@ -2188,7 +2187,7 @@ void append_path_component(wcstring &path, const wcstring &component) {
}
extern "C" {
__attribute__((noinline)) void debug_thread_error(void) {
[[gnu::noinline]] void debug_thread_error(void) {
while (1) sleep(9999999);
}
}

View File

@ -171,9 +171,8 @@ enum selection_direction_t {
///
/// will print the string 'fish: Pi = 3.141', given that debug_level is 1 or higher, and that
/// program_name is 'fish'.
void __attribute__((noinline)) debug_impl(int level, const char *msg, ...)
__attribute__((format(printf, 2, 3)));
void __attribute__((noinline)) debug_impl(int level, const wchar_t *msg, ...);
[[gnu::noinline, gnu::format(printf, 2, 3)]] void debug_impl(int level, const char *msg, ...);
[[gnu::noinline]] void debug_impl(int level, const wchar_t *msg, ...);
/// The verbosity level of fish. If a call to debug has a severity level higher than \c debug_level,
/// it will not be printed.
@ -888,7 +887,7 @@ constexpr bool is_cygwin() {
}
extern "C" {
__attribute__((noinline)) void debug_thread_error(void);
[[gnu::noinline]] void debug_thread_error(void);
}
/// Converts from wide char to digit in the specified base. If d is not a valid digit in the

View File

@ -74,7 +74,7 @@ int fish_mkstemp_cloexec(char *name_template) {
/// building on Linux) these should end up just being stripped, as they are static functions that
/// are not referenced in this file.
// cppcheck-suppress unusedFunction
__attribute__((unused)) static wchar_t *wcsdup_fallback(const wchar_t *in) {
[[gnu::unused]] static wchar_t *wcsdup_fallback(const wchar_t *in) {
size_t len = wcslen(in);
wchar_t *out = (wchar_t *)malloc(sizeof(wchar_t) * (len + 1));
if (out == 0) {
@ -85,7 +85,7 @@ __attribute__((unused)) static wchar_t *wcsdup_fallback(const wchar_t *in) {
return out;
}
__attribute__((unused)) static int wcscasecmp_fallback(const wchar_t *a, const wchar_t *b) {
[[gnu::unused]] static int wcscasecmp_fallback(const wchar_t *a, const wchar_t *b) {
if (*a == 0) {
return *b == 0 ? 0 : -1;
} else if (*b == 0) {
@ -98,7 +98,7 @@ __attribute__((unused)) static int wcscasecmp_fallback(const wchar_t *a, const w
return wcscasecmp_fallback(a + 1, b + 1);
}
__attribute__((unused)) static int wcsncasecmp_fallback(const wchar_t *a, const wchar_t *b,
[[gnu::unused]] static int wcsncasecmp_fallback(const wchar_t *a, const wchar_t *b,
size_t count) {
if (count == 0) return 0;

View File

@ -78,9 +78,9 @@ char *tparm_solaris_kludge(char *str, long p1 = 0, long p2 = 0, long p3 = 0, lon
// We have to explicitly redeclare these as weak,
// since we are forced to set the MIN_REQUIRED availability macro to 10.7
// to use libc++, which in turn exposes these as strong
wchar_t *wcsdup(const wchar_t *) __attribute__((weak_import));
int wcscasecmp(const wchar_t *, const wchar_t *) __attribute__((weak_import));
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t n) __attribute__((weak_import));
[[clang::weak_import]] wchar_t *wcsdup(const wchar_t *);
[[clang::weak_import]] int wcscasecmp(const wchar_t *, const wchar_t *);
[[clang::weak_import]] int wcsncasecmp(const wchar_t *, const wchar_t *, size_t n);
wchar_t *wcsdup_use_weak(const wchar_t *);
int wcscasecmp_use_weak(const wchar_t *, const wchar_t *);
int wcsncasecmp_use_weak(const wchar_t *s1, const wchar_t *s2, size_t n);