use [[gnu::pure]] instead of gcc_pure

This is semi-standard and doesn't require the util/Compiler.h header.
This commit is contained in:
Max Kellermann 2021-02-08 14:59:40 +01:00 committed by Max Kellermann
parent 01af2778ab
commit 6cdb3ff21e
20 changed files with 61 additions and 80 deletions

View File

@ -30,8 +30,6 @@
#ifndef FILE_DESCRIPTOR_HXX #ifndef FILE_DESCRIPTOR_HXX
#define FILE_DESCRIPTOR_HXX #define FILE_DESCRIPTOR_HXX
#include "util/Compiler.h"
#include <cstddef> #include <cstddef>
#include <utility> #include <utility>
@ -76,25 +74,25 @@ public:
/** /**
* Ask the kernel whether this is a valid file descriptor. * Ask the kernel whether this is a valid file descriptor.
*/ */
gcc_pure [[gnu::pure]]
bool IsValid() const noexcept; bool IsValid() const noexcept;
/** /**
* Ask the kernel whether this is a regular file. * Ask the kernel whether this is a regular file.
*/ */
gcc_pure [[gnu::pure]]
bool IsRegularFile() const noexcept; bool IsRegularFile() const noexcept;
/** /**
* Ask the kernel whether this is a pipe. * Ask the kernel whether this is a pipe.
*/ */
gcc_pure [[gnu::pure]]
bool IsPipe() const noexcept; bool IsPipe() const noexcept;
/** /**
* Ask the kernel whether this is a socket descriptor. * Ask the kernel whether this is a socket descriptor.
*/ */
gcc_pure [[gnu::pure]]
bool IsSocket() const noexcept; bool IsSocket() const noexcept;
#endif #endif
@ -219,7 +217,7 @@ public:
return lseek(Get(), offset, SEEK_CUR); return lseek(Get(), offset, SEEK_CUR);
} }
gcc_pure [[gnu::pure]]
off_t Tell() const noexcept { off_t Tell() const noexcept {
return lseek(Get(), 0, SEEK_CUR); return lseek(Get(), 0, SEEK_CUR);
} }
@ -227,7 +225,7 @@ public:
/** /**
* Returns the size of the file in bytes, or -1 on error. * Returns the size of the file in bytes, or -1 on error.
*/ */
gcc_pure [[gnu::pure]]
off_t GetSize() const noexcept; off_t GetSize() const noexcept;
ssize_t Read(void *buffer, std::size_t length) noexcept { ssize_t Read(void *buffer, std::size_t length) noexcept {
@ -256,7 +254,7 @@ public:
int WaitReadable(int timeout) const noexcept; int WaitReadable(int timeout) const noexcept;
int WaitWritable(int timeout) const noexcept; int WaitWritable(int timeout) const noexcept;
gcc_pure [[gnu::pure]]
bool IsReadyForWriting() const noexcept; bool IsReadyForWriting() const noexcept;
#endif #endif
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2019 Max Kellermann <max.kellermann@gmail.com> * Copyright 2016-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2016-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -31,7 +31,6 @@
#define NET_ADDRESS_INFO_HXX #define NET_ADDRESS_INFO_HXX
#include "SocketAddress.hxx" #include "SocketAddress.hxx"
#include "util/Compiler.h"
#include <utility> #include <utility>
@ -109,7 +108,7 @@ public:
* to an IPv6 wildcard address also allows accepting IPv4 * to an IPv6 wildcard address also allows accepting IPv4
* connections. * connections.
*/ */
gcc_pure [[gnu::pure]]
const AddressInfo &GetBest() const; const AddressInfo &GetBest() const;
class const_iterator { class const_iterator {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,7 +32,6 @@
#include "SocketAddress.hxx" // IWYU pragma: export #include "SocketAddress.hxx" // IWYU pragma: export
#include "Features.hxx" #include "Features.hxx"
#include "util/Compiler.h"
#include <utility> #include <utility>
@ -87,18 +86,18 @@ public:
} }
template<typename T> template<typename T>
gcc_pure [[gnu::pure]]
bool operator==(T &&other) const noexcept { bool operator==(T &&other) const noexcept {
return (SocketAddress)*this == std::forward<T>(other); return (SocketAddress)*this == std::forward<T>(other);
} }
template<typename T> template<typename T>
gcc_pure [[gnu::pure]]
bool operator!=(T &&other) const noexcept { bool operator!=(T &&other) const noexcept {
return !(*this == std::forward<T>(other)); return !(*this == std::forward<T>(other));
} }
gcc_const [[gnu::const]]
static AllocatedSocketAddress Null() noexcept { static AllocatedSocketAddress Null() noexcept {
return AllocatedSocketAddress(nullptr, 0); return AllocatedSocketAddress(nullptr, 0);
} }
@ -145,13 +144,13 @@ public:
/** /**
* @see SocketAddress::GetLocalRaw() * @see SocketAddress::GetLocalRaw()
*/ */
gcc_pure [[gnu::pure]]
StringView GetLocalRaw() const noexcept; StringView GetLocalRaw() const noexcept;
/** /**
* @see SocketAddress::GetLocalPath() * @see SocketAddress::GetLocalPath()
*/ */
gcc_pure [[gnu::pure]]
const char *GetLocalPath() const noexcept { const char *GetLocalPath() const noexcept {
return ((SocketAddress)*this).GetLocalPath(); return ((SocketAddress)*this).GetLocalPath();
} }
@ -176,7 +175,7 @@ public:
/** /**
* Extract the port number. Returns 0 if not applicable. * Extract the port number. Returns 0 if not applicable.
*/ */
gcc_pure [[gnu::pure]]
unsigned GetPort() const noexcept { unsigned GetPort() const noexcept {
return ((SocketAddress)*this).GetPort(); return ((SocketAddress)*this).GetPort();
} }

View File

@ -34,7 +34,6 @@
#define NET_HOST_PARSER_HXX #define NET_HOST_PARSER_HXX
#include "util/StringView.hxx" #include "util/StringView.hxx"
#include "util/Compiler.h"
/** /**
* Result type for ExtractHost(). * Result type for ExtractHost().
@ -69,7 +68,7 @@ struct ExtractHostResult {
* *
* @param src the input string * @param src the input string
*/ */
gcc_pure [[gnu::pure]]
ExtractHostResult ExtractHostResult
ExtractHost(const char *src) noexcept; ExtractHost(const char *src) noexcept;

View File

@ -32,7 +32,6 @@
#include "SocketAddress.hxx" #include "SocketAddress.hxx"
#include "util/ByteOrder.hxx" #include "util/ByteOrder.hxx"
#include "util/Compiler.h"
#include <cstdint> #include <cstdint>
@ -179,7 +178,7 @@ public:
/** /**
* Is this the IPv6 wildcard address (in6addr_any)? * Is this the IPv6 wildcard address (in6addr_any)?
*/ */
gcc_pure [[gnu::pure]]
bool IsAny() const noexcept; bool IsAny() const noexcept;
/** /**
@ -195,14 +194,14 @@ public:
/** /**
* Convert "::ffff:127.0.0.1" to "127.0.0.1". * Convert "::ffff:127.0.0.1" to "127.0.0.1".
*/ */
gcc_pure [[gnu::pure]]
IPv4Address UnmapV4() const noexcept; IPv4Address UnmapV4() const noexcept;
/** /**
* Bit-wise AND of two addresses. This is useful for netmask * Bit-wise AND of two addresses. This is useful for netmask
* calculations. * calculations.
*/ */
gcc_pure [[gnu::pure]]
IPv6Address operator&(const IPv6Address &other) const; IPv6Address operator&(const IPv6Address &other) const;
private: private:

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -31,7 +31,6 @@
#define SOCKET_ADDRESS_HXX #define SOCKET_ADDRESS_HXX
#include "Features.hxx" #include "Features.hxx"
#include "util/Compiler.h"
#include <cstddef> #include <cstddef>
@ -118,14 +117,14 @@ public:
* "size" attribute includes the null terminator. Returns * "size" attribute includes the null terminator. Returns
* nullptr if not applicable. * nullptr if not applicable.
*/ */
gcc_pure [[gnu::pure]]
StringView GetLocalRaw() const noexcept; StringView GetLocalRaw() const noexcept;
/** /**
* Returns the local socket path or nullptr if not applicable * Returns the local socket path or nullptr if not applicable
* (or if the path is corrupt). * (or if the path is corrupt).
*/ */
gcc_pure [[gnu::pure]]
const char *GetLocalPath() const noexcept; const char *GetLocalPath() const noexcept;
#endif #endif
@ -133,25 +132,25 @@ public:
/** /**
* Is this the IPv6 wildcard address (in6addr_any)? * Is this the IPv6 wildcard address (in6addr_any)?
*/ */
gcc_pure [[gnu::pure]]
bool IsV6Any() const noexcept; bool IsV6Any() const noexcept;
/** /**
* Is this an IPv4 address mapped inside struct sockaddr_in6? * Is this an IPv4 address mapped inside struct sockaddr_in6?
*/ */
gcc_pure [[gnu::pure]]
bool IsV4Mapped() const noexcept; bool IsV4Mapped() const noexcept;
/** /**
* Convert "::ffff:127.0.0.1" to "127.0.0.1". * Convert "::ffff:127.0.0.1" to "127.0.0.1".
*/ */
gcc_pure [[gnu::pure]]
IPv4Address UnmapV4() const noexcept; IPv4Address UnmapV4() const noexcept;
/** /**
* Extract the port number. Returns 0 if not applicable. * Extract the port number. Returns 0 if not applicable.
*/ */
gcc_pure [[gnu::pure]]
unsigned GetPort() const noexcept; unsigned GetPort() const noexcept;
#endif #endif
@ -162,10 +161,10 @@ public:
* much for anything else. Returns nullptr if the address is * much for anything else. Returns nullptr if the address is
* not supported. * not supported.
*/ */
gcc_pure [[gnu::pure]]
ConstBuffer<void> GetSteadyPart() const noexcept; ConstBuffer<void> GetSteadyPart() const noexcept;
gcc_pure [[gnu::pure]]
bool operator==(const SocketAddress other) const noexcept; bool operator==(const SocketAddress other) const noexcept;
bool operator!=(const SocketAddress other) const noexcept { bool operator!=(const SocketAddress other) const noexcept {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -90,13 +90,13 @@ public:
* Determine the socket type, i.e. SOCK_STREAM, SOCK_DGRAM or * Determine the socket type, i.e. SOCK_STREAM, SOCK_DGRAM or
* SOCK_SEQPACKET. Returns -1 on error. * SOCK_SEQPACKET. Returns -1 on error.
*/ */
gcc_pure [[gnu::pure]]
int GetType() const noexcept; int GetType() const noexcept;
/** /**
* Is this a stream socket? * Is this a stream socket?
*/ */
gcc_pure [[gnu::pure]]
bool IsStream() const noexcept; bool IsStream() const noexcept;
using FileDescriptor::Get; using FileDescriptor::Get;
@ -167,7 +167,7 @@ public:
* Receive peer credentials (SO_PEERCRED). On error, the pid * Receive peer credentials (SO_PEERCRED). On error, the pid
* is -1. * is -1.
*/ */
gcc_pure [[gnu::pure]]
struct ucred GetPeerCredentials() const noexcept; struct ucred GetPeerCredentials() const noexcept;
#endif #endif
@ -226,10 +226,10 @@ public:
bool Connect(SocketAddress address) noexcept; bool Connect(SocketAddress address) noexcept;
gcc_pure [[gnu::pure]]
StaticSocketAddress GetLocalAddress() const noexcept; StaticSocketAddress GetLocalAddress() const noexcept;
gcc_pure [[gnu::pure]]
StaticSocketAddress GetPeerAddress() const noexcept; StaticSocketAddress GetPeerAddress() const noexcept;
ssize_t Read(void *buffer, size_t length) noexcept; ssize_t Read(void *buffer, size_t length) noexcept;

View File

@ -30,7 +30,6 @@
#ifndef SOCKET_ERROR_HXX #ifndef SOCKET_ERROR_HXX
#define SOCKET_ERROR_HXX #define SOCKET_ERROR_HXX
#include "util/Compiler.h"
#include "system/Error.hxx" #include "system/Error.hxx"
#ifdef _WIN32 #ifdef _WIN32
@ -41,7 +40,7 @@ typedef DWORD socket_error_t;
typedef int socket_error_t; typedef int socket_error_t;
#endif #endif
gcc_pure [[gnu::pure]]
static inline socket_error_t static inline socket_error_t
GetSocketError() noexcept GetSocketError() noexcept
{ {
@ -128,7 +127,7 @@ IsSocketErrorAcceptWouldBlock(socket_error_t code) noexcept
#endif #endif
} }
gcc_const [[gnu::const]]
static inline bool static inline bool
IsSocketErrorInterruped(socket_error_t code) noexcept IsSocketErrorInterruped(socket_error_t code) noexcept
{ {
@ -139,7 +138,7 @@ IsSocketErrorInterruped(socket_error_t code) noexcept
#endif #endif
} }
gcc_const [[gnu::const]]
static inline bool static inline bool
IsSocketErrorClosed(socket_error_t code) noexcept IsSocketErrorClosed(socket_error_t code) noexcept
{ {
@ -171,7 +170,7 @@ public:
} }
}; };
gcc_const [[gnu::const]]
static inline std::system_error static inline std::system_error
MakeSocketError(socket_error_t code, const char *msg) noexcept MakeSocketError(socket_error_t code, const char *msg) noexcept
{ {
@ -182,7 +181,7 @@ MakeSocketError(socket_error_t code, const char *msg) noexcept
#endif #endif
} }
gcc_pure [[gnu::pure]]
static inline std::system_error static inline std::system_error
MakeSocketError(const char *msg) noexcept MakeSocketError(const char *msg) noexcept
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,7 +32,6 @@
#include "SocketAddress.hxx" // IWYU pragma: export #include "SocketAddress.hxx" // IWYU pragma: export
#include "Features.hxx" #include "Features.hxx"
#include "util/Compiler.h"
#include <cassert> #include <cassert>
@ -120,7 +119,7 @@ public:
/** /**
* @see SocketAddress::GetLocalRaw() * @see SocketAddress::GetLocalRaw()
*/ */
gcc_pure [[gnu::pure]]
StringView GetLocalRaw() const noexcept; StringView GetLocalRaw() const noexcept;
#endif #endif
@ -128,7 +127,7 @@ public:
/** /**
* Extract the port number. Returns 0 if not applicable. * Extract the port number. Returns 0 if not applicable.
*/ */
gcc_pure [[gnu::pure]]
unsigned GetPort() const noexcept { unsigned GetPort() const noexcept {
return ((SocketAddress)*this).GetPort(); return ((SocketAddress)*this).GetPort();
} }
@ -140,7 +139,7 @@ public:
bool SetPort(unsigned port) noexcept; bool SetPort(unsigned port) noexcept;
#endif #endif
gcc_pure [[gnu::pure]]
bool operator==(SocketAddress other) const noexcept { bool operator==(SocketAddress other) const noexcept {
return (SocketAddress)*this == other; return (SocketAddress)*this == other;
} }

View File

@ -30,8 +30,6 @@
#ifndef SYSTEM_ERROR_HXX #ifndef SYSTEM_ERROR_HXX
#define SYSTEM_ERROR_HXX #define SYSTEM_ERROR_HXX
#include "util/Compiler.h"
#include <system_error> // IWYU pragma: export #include <system_error> // IWYU pragma: export
#include <utility> #include <utility>
@ -160,7 +158,7 @@ FormatFileNotFound(const char *fmt, Args&&... args) noexcept
#endif #endif
} }
gcc_pure [[gnu::pure]]
inline bool inline bool
IsErrno(const std::system_error &e, int code) noexcept IsErrno(const std::system_error &e, int code) noexcept
{ {
@ -168,7 +166,7 @@ IsErrno(const std::system_error &e, int code) noexcept
e.code().value() == code; e.code().value() == code;
} }
gcc_pure [[gnu::pure]]
static inline bool static inline bool
IsFileNotFound(const std::system_error &e) noexcept IsFileNotFound(const std::system_error &e) noexcept
{ {
@ -180,7 +178,7 @@ IsFileNotFound(const std::system_error &e) noexcept
#endif #endif
} }
gcc_pure [[gnu::pure]]
static inline bool static inline bool
IsPathNotFound(const std::system_error &e) noexcept IsPathNotFound(const std::system_error &e) noexcept
{ {
@ -192,7 +190,7 @@ IsPathNotFound(const std::system_error &e) noexcept
#endif #endif
} }
gcc_pure [[gnu::pure]]
static inline bool static inline bool
IsAccessDenied(const std::system_error &e) noexcept IsAccessDenied(const std::system_error &e) noexcept
{ {

View File

@ -35,7 +35,7 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include <stdio.h> #include <stdio.h>
gcc_const [[gnu::const]]
static KernelVersionCode static KernelVersionCode
GetKernelVersionCode() noexcept GetKernelVersionCode() noexcept
{ {

View File

@ -32,8 +32,6 @@
#pragma once #pragma once
#include "util/Compiler.h"
class KernelVersionCode { class KernelVersionCode {
unsigned value = 0; unsigned value = 0;
@ -53,6 +51,6 @@ public:
/** /**
* Is the currently running Linux kernel at least the given version? * Is the currently running Linux kernel at least the given version?
*/ */
gcc_const [[gnu::const]]
bool bool
IsKernelVersionOrNewer(KernelVersionCode v) noexcept; IsKernelVersionOrNewer(KernelVersionCode v) noexcept;

View File

@ -47,7 +47,7 @@ public:
ClockCache(const ClockCache &) = delete; ClockCache(const ClockCache &) = delete;
ClockCache &operator=(const ClockCache &) = delete; ClockCache &operator=(const ClockCache &) = delete;
gcc_pure [[gnu::pure]]
const auto &now() const noexcept { const auto &now() const noexcept {
if (value <= value_type()) if (value <= value_type())
value = Clock::now(); value = Clock::now();

View File

@ -72,7 +72,7 @@ LocalTime(std::chrono::system_clock::time_point tp)
/** /**
* Determine the time zone offset in a portable way. * Determine the time zone offset in a portable way.
*/ */
gcc_const [[gnu::const]]
static time_t static time_t
GetTimeZoneOffset() noexcept GetTimeZoneOffset() noexcept
{ {

View File

@ -33,8 +33,6 @@
#ifndef TIME_CONVERT_HXX #ifndef TIME_CONVERT_HXX
#define TIME_CONVERT_HXX #define TIME_CONVERT_HXX
#include "util/Compiler.h"
#include <chrono> #include <chrono>
/** /**
@ -56,18 +54,18 @@ LocalTime(std::chrono::system_clock::time_point tp);
/** /**
* Convert a UTC-based "struct tm" to a UTC-based time point. * Convert a UTC-based "struct tm" to a UTC-based time point.
*/ */
gcc_pure [[gnu::pure]]
std::chrono::system_clock::time_point std::chrono::system_clock::time_point
TimeGm(struct tm &tm) noexcept; TimeGm(struct tm &tm) noexcept;
/** /**
* Convert a local "struct tm" to a UTC-based time point. * Convert a local "struct tm" to a UTC-based time point.
*/ */
gcc_pure [[gnu::pure]]
std::chrono::system_clock::time_point std::chrono::system_clock::time_point
MakeTime(struct tm &tm) noexcept; MakeTime(struct tm &tm) noexcept;
gcc_pure [[gnu::pure]]
std::chrono::steady_clock::duration std::chrono::steady_clock::duration
ToSteadyClockDuration(const struct timeval &tv) noexcept; ToSteadyClockDuration(const struct timeval &tv) noexcept;

View File

@ -33,8 +33,6 @@
#ifndef TIME_ISO8601_HXX #ifndef TIME_ISO8601_HXX
#define TIME_ISO8601_HXX #define TIME_ISO8601_HXX
#include "util/Compiler.h"
#include <chrono> #include <chrono>
#include <cstddef> #include <cstddef>
#include <utility> #include <utility>
@ -42,11 +40,11 @@
struct tm; struct tm;
template<size_t CAPACITY> class StringBuffer; template<size_t CAPACITY> class StringBuffer;
gcc_pure [[gnu::pure]]
StringBuffer<64> StringBuffer<64>
FormatISO8601(const struct tm &tm) noexcept; FormatISO8601(const struct tm &tm) noexcept;
gcc_pure [[gnu::pure]]
StringBuffer<64> StringBuffer<64>
FormatISO8601(std::chrono::system_clock::time_point tp); FormatISO8601(std::chrono::system_clock::time_point tp);

View File

@ -32,8 +32,6 @@
#pragma once #pragma once
#include "util/Compiler.h"
#include <chrono> #include <chrono>
struct tm; struct tm;
@ -42,7 +40,7 @@ struct tm;
* Calculates the preceding midnight time point in the current time * Calculates the preceding midnight time point in the current time
* zone. * zone.
*/ */
gcc_const [[gnu::const]]
std::chrono::system_clock::time_point std::chrono::system_clock::time_point
PrecedingMidnightLocal(std::chrono::system_clock::time_point t) noexcept; PrecedingMidnightLocal(std::chrono::system_clock::time_point t) noexcept;