From a742e1fc71110a7f4ee3a3c20f7f09c44e4bebdc Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Tue, 26 Apr 2022 20:19:31 +0200
Subject: [PATCH] util/PeakBuffer, ...: use [[gnu::]] attributes

---
 src/util/ASCII.hxx          |  8 ++++----
 src/util/FormatString.hxx   |  5 +++--
 src/util/HugeAllocator.cxx  |  3 +--
 src/util/PeakBuffer.hxx     |  6 ++----
 src/util/ReusableArray.hxx  |  2 +-
 src/util/SliceBuffer.hxx    |  1 -
 src/util/UriQueryParser.hxx |  4 +---
 src/util/UriRelative.cxx    |  1 +
 src/util/UriRelative.hxx    | 10 ++++------
 src/util/UriUtil.cxx        |  2 +-
 src/util/VarSize.hxx        |  6 ++----
 11 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/src/util/ASCII.hxx b/src/util/ASCII.hxx
index df51d8650..a9e4742db 100644
--- a/src/util/ASCII.hxx
+++ b/src/util/ASCII.hxx
@@ -41,7 +41,7 @@
  * Determine whether two strings are equal, ignoring case for ASCII
  * letters.
  */
-gcc_pure gcc_nonnull_all
+[[gnu::pure]] [[gnu::nonnull]]
 static inline bool
 StringEqualsCaseASCII(const char *a, const char *b) noexcept
 {
@@ -56,7 +56,7 @@ StringEqualsCaseASCII(const char *a, const char *b) noexcept
 	return strcasecmp(a, b) == 0;
 }
 
-gcc_pure gcc_nonnull_all
+[[gnu::pure]] [[gnu::nonnull]]
 static inline bool
 StringEqualsCaseASCII(const char *a, const char *b, size_t n) noexcept
 {
@@ -71,7 +71,7 @@ StringEqualsCaseASCII(const char *a, const char *b, size_t n) noexcept
 	return strncasecmp(a, b, n) == 0;
 }
 
-gcc_pure gcc_nonnull_all
+[[gnu::pure]] [[gnu::nonnull]]
 static inline bool
 StringStartsWithCaseASCII(const char *haystack,
 			  std::string_view needle) noexcept
@@ -79,7 +79,7 @@ StringStartsWithCaseASCII(const char *haystack,
 	return StringEqualsCaseASCII(haystack, needle.data(), needle.length());
 }
 
-gcc_pure gcc_nonnull_all
+[[gnu::pure]] [[gnu::nonnull]]
 static inline const char *
 StringAfterPrefixCaseASCII(const char *haystack,
 			   std::string_view needle) noexcept
diff --git a/src/util/FormatString.hxx b/src/util/FormatString.hxx
index 83f112a91..e794d129a 100644
--- a/src/util/FormatString.hxx
+++ b/src/util/FormatString.hxx
@@ -29,14 +29,15 @@ class AllocatedString;
 /**
  * Format into an #AllocatedString.
  */
-gcc_nonnull_all
+[[gnu::nonnull]]
 AllocatedString
 FormatStringV(const char *fmt, std::va_list args) noexcept;
 
 /**
  * Format into an #AllocatedString.
  */
-gcc_nonnull(1) gcc_printf(1,2)
+[[gnu::nonnull(1)]]
+gcc_printf(1,2)
 AllocatedString
 FormatString(const char *fmt, ...) noexcept;
 
diff --git a/src/util/HugeAllocator.cxx b/src/util/HugeAllocator.cxx
index 000595be6..ce3ea1c60 100644
--- a/src/util/HugeAllocator.cxx
+++ b/src/util/HugeAllocator.cxx
@@ -28,7 +28,6 @@
  */
 
 #include "HugeAllocator.hxx"
-#include "Compiler.h"
 
 #include <new>
 
@@ -44,7 +43,7 @@
 /**
  * Round up the parameter, make it page-aligned.
  */
-gcc_const
+[[gnu::const]]
 static size_t
 AlignToPageSize(size_t size) noexcept
 {
diff --git a/src/util/PeakBuffer.hxx b/src/util/PeakBuffer.hxx
index febf8bd73..ba87da91c 100644
--- a/src/util/PeakBuffer.hxx
+++ b/src/util/PeakBuffer.hxx
@@ -20,8 +20,6 @@
 #ifndef MPD_PEAK_BUFFER_HXX
 #define MPD_PEAK_BUFFER_HXX
 
-#include "Compiler.h"
-
 #include <cstddef>
 
 template<typename T> struct WritableBuffer;
@@ -59,10 +57,10 @@ public:
 		return normal_size + peak_size;
 	}
 
-	gcc_pure
+	[[gnu::pure]]
 	bool empty() const noexcept;
 
-	gcc_pure
+	[[gnu::pure]]
 	WritableBuffer<void> Read() const noexcept;
 
 	void Consume(std::size_t length) noexcept;
diff --git a/src/util/ReusableArray.hxx b/src/util/ReusableArray.hxx
index 5ff2aa4a6..06d0f08d2 100644
--- a/src/util/ReusableArray.hxx
+++ b/src/util/ReusableArray.hxx
@@ -83,7 +83,7 @@ public:
 	 * Get the buffer, and guarantee a minimum size.  This buffer
 	 * becomes invalid with the next Get() call.
 	 */
-	gcc_malloc gcc_returns_nonnull
+	[[gnu::malloc]] [[gnu::returns_nonnull]]
 	T *Get(size_t size) {
 		if (gcc_unlikely(size > capacity)) {
 			/* too small: grow */
diff --git a/src/util/SliceBuffer.hxx b/src/util/SliceBuffer.hxx
index 0f1ec71e1..a43767b75 100644
--- a/src/util/SliceBuffer.hxx
+++ b/src/util/SliceBuffer.hxx
@@ -21,7 +21,6 @@
 #define MPD_SLICE_BUFFER_HXX
 
 #include "HugeAllocator.hxx"
-#include "Compiler.h"
 
 #include <cassert>
 #include <cstddef>
diff --git a/src/util/UriQueryParser.hxx b/src/util/UriQueryParser.hxx
index b098e5f06..c9b52d4a8 100644
--- a/src/util/UriQueryParser.hxx
+++ b/src/util/UriQueryParser.hxx
@@ -30,8 +30,6 @@
 #ifndef URI_QUERY_PARSER_HXX
 #define URI_QUERY_PARSER_HXX
 
-#include "Compiler.h"
-
 struct StringView;
 
 /**
@@ -41,7 +39,7 @@ struct StringView;
  * @return the raw value (pointing into the #query_string parameter)
  * or nullptr if the parameter does not exist
  */
-gcc_pure
+[[gnu::pure]]
 StringView
 UriFindRawQueryParameter(StringView query_string, StringView name) noexcept;
 
diff --git a/src/util/UriRelative.cxx b/src/util/UriRelative.cxx
index 2ff1b046f..cfaaa5512 100644
--- a/src/util/UriRelative.cxx
+++ b/src/util/UriRelative.cxx
@@ -31,6 +31,7 @@
 #include "UriExtract.hxx"
 #include "StringAPI.hxx"
 #include "StringCompare.hxx"
+#include "Compiler.h"
 
 #include <cassert>
 
diff --git a/src/util/UriRelative.hxx b/src/util/UriRelative.hxx
index 2ef0957e4..d2a4617c2 100644
--- a/src/util/UriRelative.hxx
+++ b/src/util/UriRelative.hxx
@@ -30,8 +30,6 @@
 #ifndef URI_RELATIVE_HXX
 #define URI_RELATIVE_HXX
 
-#include "Compiler.h"
-
 #include <string>
 #include <string_view>
 
@@ -40,11 +38,11 @@
  * specified by #parent.  If the strings are equal, the function
  * returns false.
  */
-gcc_pure gcc_nonnull_all
+[[gnu::pure]] [[gnu::nonnull]]
 bool
 uri_is_child(const char *parent, const char *child) noexcept;
 
-gcc_pure gcc_nonnull_all
+[[gnu::pure]] [[gnu::nonnull]]
 bool
 uri_is_child_or_same(const char *parent, const char *child) noexcept;
 
@@ -52,11 +50,11 @@ uri_is_child_or_same(const char *parent, const char *child) noexcept;
  * Translate the given URI in the context of #base.  For example,
  * uri_apply_base("foo", "http://bar/a/")=="http://bar/a/foo".
  */
-gcc_pure
+[[gnu::pure]]
 std::string
 uri_apply_base(std::string_view uri, std::string_view base) noexcept;
 
-gcc_pure
+[[gnu::pure]]
 std::string
 uri_apply_relative(std::string_view relative_uri,
 		   std::string_view base_uri) noexcept;
diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx
index a94edae89..aa45de910 100644
--- a/src/util/UriUtil.cxx
+++ b/src/util/UriUtil.cxx
@@ -70,7 +70,7 @@ uri_safe_local(const char *uri) noexcept
 	}
 }
 
-gcc_pure
+[[gnu::pure]]
 static const char *
 SkipUriScheme(const char *uri) noexcept
 {
diff --git a/src/util/VarSize.hxx b/src/util/VarSize.hxx
index 9b5ad4953..6bc008935 100644
--- a/src/util/VarSize.hxx
+++ b/src/util/VarSize.hxx
@@ -30,8 +30,6 @@
 #ifndef MPD_VAR_SIZE_HXX
 #define MPD_VAR_SIZE_HXX
 
-#include "Compiler.h"
-
 #include <type_traits>
 #include <utility>
 #include <new>
@@ -49,7 +47,7 @@
  * #T
  */
 template<class T, typename... Args>
-gcc_malloc gcc_returns_nonnull
+[[gnu::malloc]] [[gnu::returns_nonnull]]
 T *
 NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args)
 {
@@ -71,7 +69,7 @@ NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args)
 }
 
 template<typename T>
-gcc_nonnull_all
+[[gnu::nonnull]]
 void
 DeleteVarSize(T *instance)
 {