more [[gnu::...]] attributes

This commit is contained in:
Max Kellermann
2021-10-13 11:28:04 +02:00
parent 1c4b484a56
commit f510564d9d
135 changed files with 361 additions and 514 deletions

View File

@@ -20,7 +20,6 @@
#ifndef MPD_FS_ALLOCATED_PATH_HXX
#define MPD_FS_ALLOCATED_PATH_HXX
#include "util/Compiler.h"
#include "Traits.hxx"
#include "Path.hxx"
@@ -81,7 +80,7 @@ public:
~AllocatedPath() noexcept;
gcc_pure
[[gnu::pure]]
operator Path() const noexcept {
return Path::FromFS(c_str());
}
@@ -89,40 +88,40 @@ public:
/**
* Join two path components with the path separator.
*/
gcc_pure
[[gnu::pure]]
static AllocatedPath Build(string_view a, string_view b) noexcept {
return AllocatedPath(Traits::Build(a, b));
}
gcc_pure gcc_nonnull_all
[[gnu::pure]]
static AllocatedPath Build(Path a, string_view b) noexcept {
return Build(a.c_str(), b);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]]
static AllocatedPath Build(Path a, Path b) noexcept {
return Build(a, b.c_str());
}
gcc_pure gcc_nonnull_all
[[gnu::pure]]
static AllocatedPath Build(string_view a,
const AllocatedPath &b) noexcept {
return Build(a, b.value);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]]
static AllocatedPath Build(const AllocatedPath &a,
string_view b) noexcept {
return Build(a.value, b);
}
gcc_pure
[[gnu::pure]]
static AllocatedPath Build(const AllocatedPath &a,
const AllocatedPath &b) noexcept {
return Build(a.value, b.value);
}
gcc_pure
[[gnu::pure]]
static AllocatedPath Apply(Path base, Path path) noexcept {
return Traits::Apply(base.c_str(), path.c_str());
}
@@ -131,17 +130,17 @@ public:
* Convert a C string that is already in the filesystem
* character set to a #Path instance.
*/
gcc_pure
[[gnu::pure]]
static AllocatedPath FromFS(const_pointer fs) noexcept {
return AllocatedPath(fs);
}
gcc_pure
[[gnu::pure]]
static AllocatedPath FromFS(string_view fs) noexcept {
return AllocatedPath(fs);
}
gcc_pure
[[gnu::pure]]
static AllocatedPath FromFS(const_pointer _begin,
const_pointer _end) noexcept {
return AllocatedPath(_begin, _end);
@@ -151,13 +150,13 @@ public:
* Convert a C++ string that is already in the filesystem
* character set to a #Path instance.
*/
gcc_pure
[[gnu::pure]]
static AllocatedPath FromFS(string &&fs) noexcept {
return AllocatedPath(std::move(fs));
}
#ifdef ANDROID
gcc_pure
[[gnu::pure]]
static AllocatedPath FromUTF8(std::string &&utf8) noexcept {
/* on Android, the filesystem charset is hard-coded to
UTF-8 */
@@ -173,7 +172,7 @@ public:
* Convert a UTF-8 C string to an #AllocatedPath instance.
* Returns return a "nulled" instance on error.
*/
gcc_pure
[[gnu::pure]]
static AllocatedPath FromUTF8(std::string_view path_utf8) noexcept;
static AllocatedPath FromUTF8(const char *path_utf8) noexcept {
@@ -199,12 +198,12 @@ public:
return *this;
}
gcc_pure
[[gnu::pure]]
bool operator==(const AllocatedPath &other) const noexcept {
return value == other.value;
}
gcc_pure
[[gnu::pure]]
bool operator!=(const AllocatedPath &other) const noexcept {
return value != other.value;
}
@@ -238,7 +237,7 @@ public:
* @return the length of this string in number of "value_type"
* elements (which may not be the number of characters).
*/
gcc_pure
[[gnu::pure]]
size_t length() const noexcept {
return value.length();
}
@@ -248,7 +247,7 @@ public:
* pointer is invalidated whenever the value of life of this
* instance ends.
*/
gcc_pure
[[gnu::pure]]
const_pointer c_str() const noexcept {
return value.c_str();
}
@@ -257,7 +256,7 @@ public:
* Returns a pointer to the raw value, not necessarily
* null-terminated.
*/
gcc_pure
[[gnu::pure]]
const_pointer data() const noexcept {
return value.data();
}
@@ -267,7 +266,7 @@ public:
* Returns empty string on error or if this instance is "nulled"
* (#IsNull returns true).
*/
gcc_pure
[[gnu::pure]]
std::string ToUTF8() const noexcept {
return ((Path)*this).ToUTF8();
}
@@ -280,7 +279,7 @@ public:
* Gets directory name of this path.
* Returns a "nulled" instance on error.
*/
gcc_pure
[[gnu::pure]]
AllocatedPath GetDirectoryName() const noexcept {
return ((Path)*this).GetDirectoryName();
}
@@ -291,12 +290,12 @@ public:
* empty string if the given path equals this object or
* nullptr on mismatch.
*/
gcc_pure
[[gnu::pure]]
const_pointer Relative(Path other_fs) const noexcept {
return Traits::Relative(c_str(), other_fs.c_str());
}
gcc_pure
[[gnu::pure]]
const_pointer GetSuffix() const noexcept {
return ((Path)*this).GetSuffix();
}
@@ -306,7 +305,7 @@ public:
*/
void ChopSeparators() noexcept;
gcc_pure
[[gnu::pure]]
bool IsAbsolute() const noexcept {
return Traits::IsAbsolute(c_str());
}

View File

@@ -20,13 +20,12 @@
#ifndef MPD_FS_CHARSET_HXX
#define MPD_FS_CHARSET_HXX
#include "util/Compiler.h"
#include "Traits.hxx"
/**
* Gets file system character set name.
*/
gcc_const
[[gnu::const]]
const char *
GetFSCharset() noexcept;

View File

@@ -30,8 +30,6 @@
#endif
#ifdef HAVE_CLASS_GLOB
#include "util/Compiler.h"
#include <string>
/**
@@ -48,7 +46,7 @@ public:
Glob(Glob &&other) noexcept = default;
Glob &operator=(Glob &&other) noexcept = default;
gcc_pure
[[gnu::pure]]
bool Check(const char *name_fs) const noexcept;
};

View File

@@ -20,7 +20,6 @@
#ifndef MPD_FS_PATH_HXX
#define MPD_FS_PATH_HXX
#include "util/Compiler.h"
#include "Traits.hxx"
#include <cassert>
@@ -88,7 +87,7 @@ public:
* @return the length of this string in number of "value_type"
* elements (which may not be the number of characters).
*/
gcc_pure
[[gnu::pure]]
size_t length() const noexcept {
assert(!IsNull());
@@ -117,7 +116,7 @@ public:
* usually rejected by MPD because its protocol cannot
* transfer newline characters).
*/
gcc_pure
[[gnu::pure]]
bool HasNewline() const noexcept {
return Traits::Find(c_str(), '\n') != nullptr;
}
@@ -127,7 +126,7 @@ public:
* Returns empty string on error or if this instance is "nulled"
* (#IsNull returns true).
*/
gcc_pure
[[gnu::pure]]
std::string ToUTF8() const noexcept;
/**
@@ -139,7 +138,7 @@ public:
* Determine the "base" file name.
* The return value points inside this object.
*/
gcc_pure
[[gnu::pure]]
Path GetBase() const noexcept {
return FromFS(Traits::GetBase(c_str()));
}
@@ -148,7 +147,7 @@ public:
* Gets directory name of this path.
* Returns a "nulled" instance on error.
*/
gcc_pure
[[gnu::pure]]
AllocatedPath GetDirectoryName() const noexcept;
/**
@@ -157,17 +156,17 @@ public:
* empty string if the given path equals this object or
* nullptr on mismatch.
*/
gcc_pure
[[gnu::pure]]
const_pointer Relative(Path other_fs) const noexcept {
return Traits::Relative(c_str(), other_fs.c_str());
}
gcc_pure
[[gnu::pure]]
bool IsAbsolute() const noexcept {
return Traits::IsAbsolute(c_str());
}
gcc_pure
[[gnu::pure]]
const_pointer GetSuffix() const noexcept;
};

View File

@@ -37,7 +37,7 @@ GetUserMusicDir() noexcept;
/**
* Obtains cache directory for the current user.
*/
gcc_pure
[[gnu::pure]]
AllocatedPath
GetUserCacheDir() noexcept;

View File

@@ -71,7 +71,7 @@ struct PathTraitsFS {
ch == SEPARATOR;
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static const_pointer FindLastSeparator(const_pointer p) noexcept {
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
@@ -100,7 +100,7 @@ struct PathTraitsFS {
#endif
}
gcc_pure
[[gnu::pure]]
static const_pointer GetFilenameSuffix(const_pointer filename) noexcept {
const_pointer dot = StringFindLast(filename, '.');
return dot != nullptr && dot > filename && dot[1] != 0
@@ -108,13 +108,13 @@ struct PathTraitsFS {
: nullptr;
}
gcc_pure
[[gnu::pure]]
static const_pointer GetPathSuffix(const_pointer path) noexcept {
return GetFilenameSuffix(GetBase(path));
}
#ifdef _WIN32
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static constexpr bool IsDrive(const_pointer p) noexcept {
return IsAlphaASCII(p[0]) && p[1] == ':';
}
@@ -124,7 +124,7 @@ struct PathTraitsFS {
}
#endif
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static bool IsAbsolute(const_pointer p) noexcept {
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
@@ -138,18 +138,18 @@ struct PathTraitsFS {
return IsSeparator(*p);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static bool IsSpecialFilename(const_pointer name) noexcept {
return (name[0] == '.' && name[1] == 0) ||
(name[0] == '.' && name[1] == '.' && name[2] == 0);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static size_t GetLength(const_pointer p) noexcept {
return StringLength(p);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static const_pointer Find(const_pointer p, value_type ch) noexcept {
return StringFind(p, ch);
}
@@ -158,7 +158,7 @@ struct PathTraitsFS {
* Determine the "base" file name of the given native path.
* The return value points inside the given string.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static const_pointer GetBase(const_pointer p) noexcept;
/**
@@ -166,7 +166,7 @@ struct PathTraitsFS {
* As a special case, returns the string "." if there is no
* separator in the given input string.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static string_view GetParent(const_pointer p) noexcept;
[[gnu::pure]]
@@ -178,10 +178,10 @@ struct PathTraitsFS {
* empty string if the given path equals this object or
* nullptr on mismatch.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static const_pointer Relative(string_view base, const_pointer other) noexcept;
gcc_pure
[[gnu::pure]]
static string_view Relative(string_view base, string_view other) noexcept;
/**
@@ -190,14 +190,14 @@ struct PathTraitsFS {
* remaining component is returned unchanged.
* If both components are empty strings, empty string is returned.
*/
gcc_pure
[[gnu::pure]]
static string Build(string_view a, string_view b) noexcept;
/**
* Interpret the given path as being relative to the given
* base, and return the concatenated path.
*/
gcc_pure
[[gnu::pure]]
static string Apply(const_pointer base,
const_pointer path) noexcept;
};
@@ -221,7 +221,7 @@ struct PathTraitsUTF8 {
return ch == SEPARATOR;
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static const_pointer FindLastSeparator(const_pointer p) noexcept {
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
@@ -236,7 +236,7 @@ struct PathTraitsUTF8 {
return StringFindLast(p.data(), SEPARATOR, p.size());
}
gcc_pure
[[gnu::pure]]
static const_pointer GetFilenameSuffix(const_pointer filename) noexcept {
const_pointer dot = StringFindLast(filename, '.');
return dot != nullptr && dot > filename && dot[1] != 0
@@ -244,13 +244,13 @@ struct PathTraitsUTF8 {
: nullptr;
}
gcc_pure
[[gnu::pure]]
static const_pointer GetPathSuffix(const_pointer path) noexcept {
return GetFilenameSuffix(GetBase(path));
}
#ifdef _WIN32
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static constexpr bool IsDrive(const_pointer p) noexcept {
return IsAlphaASCII(p[0]) && p[1] == ':';
}
@@ -260,7 +260,7 @@ struct PathTraitsUTF8 {
}
#endif
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static bool IsAbsolute(const_pointer p) noexcept {
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
@@ -281,18 +281,18 @@ struct PathTraitsUTF8 {
[[gnu::pure]] [[gnu::nonnull]]
static bool IsAbsoluteOrHasScheme(const_pointer p) noexcept;
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static bool IsSpecialFilename(const_pointer name) noexcept {
return (name[0] == '.' && name[1] == 0) ||
(name[0] == '.' && name[1] == '.' && name[2] == 0);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static size_t GetLength(const_pointer p) noexcept {
return StringLength(p);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static const_pointer Find(const_pointer p, value_type ch) noexcept {
return StringFind(p, ch);
}
@@ -301,7 +301,7 @@ struct PathTraitsUTF8 {
* Determine the "base" file name of the given UTF-8 path.
* The return value points inside the given string.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static const_pointer GetBase(const_pointer p) noexcept;
/**
@@ -309,7 +309,7 @@ struct PathTraitsUTF8 {
* As a special case, returns the string "." if there is no
* separator in the given input string.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static string_view GetParent(const_pointer p) noexcept;
[[gnu::pure]]
@@ -321,10 +321,10 @@ struct PathTraitsUTF8 {
* empty string if the given path equals this object or
* nullptr on mismatch.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static const_pointer Relative(string_view base, const_pointer other) noexcept;
gcc_pure
[[gnu::pure]]
static string_view Relative(string_view base, string_view other) noexcept;
/**
@@ -333,7 +333,7 @@ struct PathTraitsUTF8 {
* remaining component is returned unchanged.
* If both components are empty strings, empty string is returned.
*/
gcc_pure
[[gnu::pure]]
static string Build(string_view a, string_view b) noexcept;
};

View File

@@ -25,7 +25,7 @@ AutoGunzipReader::AutoGunzipReader(Reader &_next) noexcept
AutoGunzipReader::~AutoGunzipReader() noexcept = default;
gcc_pure
[[gnu::pure]]
static bool
IsGzip(const uint8_t data[4]) noexcept
{

View File

@@ -30,7 +30,6 @@
#ifndef BUFFERED_READER_HXX
#define BUFFERED_READER_HXX
#include "util/Compiler.h"
#include "util/DynamicFifoBuffer.hxx"
#include <cstddef>
@@ -64,7 +63,7 @@ public:
bool Fill(bool need_more);
gcc_pure
[[gnu::pure]]
WritableBuffer<void> Read() const noexcept {
return buffer.Read().ToVoid();
}

View File

@@ -32,7 +32,6 @@
#include "OutputStream.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/Compiler.h"
#ifndef _WIN32
#include "io/FileDescriptor.hxx"
@@ -133,7 +132,7 @@ public:
return path;
}
gcc_pure
[[gnu::pure]]
uint64_t Tell() const noexcept;
/* virtual methods from class OutputStream */

View File

@@ -32,7 +32,6 @@
#include "Reader.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/Compiler.h"
#ifdef _WIN32
#include <fileapi.h>
@@ -94,7 +93,7 @@ public:
FileInfo GetFileInfo() const;
gcc_pure
[[gnu::pure]]
uint64_t GetSize() const noexcept {
#ifdef _WIN32
LARGE_INTEGER size;
@@ -106,7 +105,7 @@ public:
#endif
}
gcc_pure
[[gnu::pure]]
uint64_t GetPosition() const noexcept {
#ifdef _WIN32
LARGE_INTEGER zero;

View File

@@ -30,8 +30,6 @@
#ifndef READER_HXX
#define READER_HXX
#include "util/Compiler.h"
#include <cstddef>
/**
@@ -52,7 +50,7 @@ public:
* @return the number of bytes read into the given buffer or 0
* on end-of-stream
*/
gcc_nonnull_all
[[gnu::nonnull]]
virtual size_t Read(void *data, size_t size) = 0;
};