From 34fa8ef2d23a7a2db40c5b4ec6273831147f4044 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Sun, 10 Feb 2019 04:20:01 -0800 Subject: [PATCH] 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]] --- src/common.cpp | 15 +++++++-------- src/common.h | 7 +++---- src/fallback.cpp | 6 +++--- src/fallback.h | 6 +++--- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 3a02dadf5..5b8f628b0 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -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); } } diff --git a/src/common.h b/src/common.h index 89488162c..95dd176af 100644 --- a/src/common.h +++ b/src/common.h @@ -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 diff --git a/src/fallback.cpp b/src/fallback.cpp index 4826426b9..a8d044d31 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -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; diff --git a/src/fallback.h b/src/fallback.h index de6771057..93745df55 100644 --- a/src/fallback.h +++ b/src/fallback.h @@ -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);