From 6cdb3ff21ed47559a055c53c3ca23f53a10930fe Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 8 Feb 2021 14:59:40 +0100 Subject: [PATCH] use [[gnu::pure]] instead of gcc_pure This is semi-standard and doesn't require the util/Compiler.h header. --- src/io/FileDescriptor.hxx | 16 +++++++--------- src/net/AddressInfo.cxx | 2 +- src/net/AddressInfo.hxx | 5 ++--- src/net/AllocatedSocketAddress.cxx | 2 +- src/net/AllocatedSocketAddress.hxx | 15 +++++++-------- src/net/HostParser.hxx | 3 +-- src/net/IPv6Address.hxx | 7 +++---- src/net/SocketAddress.cxx | 2 +- src/net/SocketAddress.hxx | 19 +++++++++---------- src/net/SocketDescriptor.hxx | 12 ++++++------ src/net/SocketError.hxx | 11 +++++------ src/net/StaticSocketAddress.hxx | 9 ++++----- src/system/Error.hxx | 10 ++++------ src/system/KernelVersion.cxx | 2 +- src/system/KernelVersion.hxx | 4 +--- src/time/ClockCache.hxx | 2 +- src/time/Convert.cxx | 2 +- src/time/Convert.hxx | 8 +++----- src/time/ISO8601.hxx | 6 ++---- src/time/Math.hxx | 4 +--- 20 files changed, 61 insertions(+), 80 deletions(-) diff --git a/src/io/FileDescriptor.hxx b/src/io/FileDescriptor.hxx index 484bfa9c5..7f9da822d 100644 --- a/src/io/FileDescriptor.hxx +++ b/src/io/FileDescriptor.hxx @@ -30,8 +30,6 @@ #ifndef FILE_DESCRIPTOR_HXX #define FILE_DESCRIPTOR_HXX -#include "util/Compiler.h" - #include #include @@ -76,25 +74,25 @@ public: /** * Ask the kernel whether this is a valid file descriptor. */ - gcc_pure + [[gnu::pure]] bool IsValid() const noexcept; /** * Ask the kernel whether this is a regular file. */ - gcc_pure + [[gnu::pure]] bool IsRegularFile() const noexcept; /** * Ask the kernel whether this is a pipe. */ - gcc_pure + [[gnu::pure]] bool IsPipe() const noexcept; /** * Ask the kernel whether this is a socket descriptor. */ - gcc_pure + [[gnu::pure]] bool IsSocket() const noexcept; #endif @@ -219,7 +217,7 @@ public: return lseek(Get(), offset, SEEK_CUR); } - gcc_pure + [[gnu::pure]] off_t Tell() const noexcept { return lseek(Get(), 0, SEEK_CUR); } @@ -227,7 +225,7 @@ public: /** * Returns the size of the file in bytes, or -1 on error. */ - gcc_pure + [[gnu::pure]] off_t GetSize() const noexcept; ssize_t Read(void *buffer, std::size_t length) noexcept { @@ -256,7 +254,7 @@ public: int WaitReadable(int timeout) const noexcept; int WaitWritable(int timeout) const noexcept; - gcc_pure + [[gnu::pure]] bool IsReadyForWriting() const noexcept; #endif }; diff --git a/src/net/AddressInfo.cxx b/src/net/AddressInfo.cxx index 9bd51dba6..11ab355d6 100644 --- a/src/net/AddressInfo.cxx +++ b/src/net/AddressInfo.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 Max Kellermann + * Copyright 2016-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/net/AddressInfo.hxx b/src/net/AddressInfo.hxx index 578c53a07..259279fdc 100644 --- a/src/net/AddressInfo.hxx +++ b/src/net/AddressInfo.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 Max Kellermann + * Copyright 2016-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,7 +31,6 @@ #define NET_ADDRESS_INFO_HXX #include "SocketAddress.hxx" -#include "util/Compiler.h" #include @@ -109,7 +108,7 @@ public: * to an IPv6 wildcard address also allows accepting IPv4 * connections. */ - gcc_pure + [[gnu::pure]] const AddressInfo &GetBest() const; class const_iterator { diff --git a/src/net/AllocatedSocketAddress.cxx b/src/net/AllocatedSocketAddress.cxx index 18be3d87c..8a179a72e 100644 --- a/src/net/AllocatedSocketAddress.cxx +++ b/src/net/AllocatedSocketAddress.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 Max Kellermann + * Copyright 2012-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/net/AllocatedSocketAddress.hxx b/src/net/AllocatedSocketAddress.hxx index 8e9393145..591723739 100644 --- a/src/net/AllocatedSocketAddress.hxx +++ b/src/net/AllocatedSocketAddress.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 Max Kellermann + * Copyright 2012-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,7 +32,6 @@ #include "SocketAddress.hxx" // IWYU pragma: export #include "Features.hxx" -#include "util/Compiler.h" #include @@ -87,18 +86,18 @@ public: } template - gcc_pure + [[gnu::pure]] bool operator==(T &&other) const noexcept { return (SocketAddress)*this == std::forward(other); } template - gcc_pure + [[gnu::pure]] bool operator!=(T &&other) const noexcept { return !(*this == std::forward(other)); } - gcc_const + [[gnu::const]] static AllocatedSocketAddress Null() noexcept { return AllocatedSocketAddress(nullptr, 0); } @@ -145,13 +144,13 @@ public: /** * @see SocketAddress::GetLocalRaw() */ - gcc_pure + [[gnu::pure]] StringView GetLocalRaw() const noexcept; /** * @see SocketAddress::GetLocalPath() */ - gcc_pure + [[gnu::pure]] const char *GetLocalPath() const noexcept { return ((SocketAddress)*this).GetLocalPath(); } @@ -176,7 +175,7 @@ public: /** * Extract the port number. Returns 0 if not applicable. */ - gcc_pure + [[gnu::pure]] unsigned GetPort() const noexcept { return ((SocketAddress)*this).GetPort(); } diff --git a/src/net/HostParser.hxx b/src/net/HostParser.hxx index c7d3b8275..561beb843 100644 --- a/src/net/HostParser.hxx +++ b/src/net/HostParser.hxx @@ -34,7 +34,6 @@ #define NET_HOST_PARSER_HXX #include "util/StringView.hxx" -#include "util/Compiler.h" /** * Result type for ExtractHost(). @@ -69,7 +68,7 @@ struct ExtractHostResult { * * @param src the input string */ -gcc_pure +[[gnu::pure]] ExtractHostResult ExtractHost(const char *src) noexcept; diff --git a/src/net/IPv6Address.hxx b/src/net/IPv6Address.hxx index eaa2db867..b0c29a360 100644 --- a/src/net/IPv6Address.hxx +++ b/src/net/IPv6Address.hxx @@ -32,7 +32,6 @@ #include "SocketAddress.hxx" #include "util/ByteOrder.hxx" -#include "util/Compiler.h" #include @@ -179,7 +178,7 @@ public: /** * Is this the IPv6 wildcard address (in6addr_any)? */ - gcc_pure + [[gnu::pure]] bool IsAny() const noexcept; /** @@ -195,14 +194,14 @@ public: /** * Convert "::ffff:127.0.0.1" to "127.0.0.1". */ - gcc_pure + [[gnu::pure]] IPv4Address UnmapV4() const noexcept; /** * Bit-wise AND of two addresses. This is useful for netmask * calculations. */ - gcc_pure + [[gnu::pure]] IPv6Address operator&(const IPv6Address &other) const; private: diff --git a/src/net/SocketAddress.cxx b/src/net/SocketAddress.cxx index 1ac78c412..c0d1737b2 100644 --- a/src/net/SocketAddress.cxx +++ b/src/net/SocketAddress.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 Max Kellermann + * Copyright 2012-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/net/SocketAddress.hxx b/src/net/SocketAddress.hxx index 8e9691e8e..ccbb571fa 100644 --- a/src/net/SocketAddress.hxx +++ b/src/net/SocketAddress.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 Max Kellermann + * Copyright 2012-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,7 +31,6 @@ #define SOCKET_ADDRESS_HXX #include "Features.hxx" -#include "util/Compiler.h" #include @@ -118,14 +117,14 @@ public: * "size" attribute includes the null terminator. Returns * nullptr if not applicable. */ - gcc_pure + [[gnu::pure]] StringView GetLocalRaw() const noexcept; /** * Returns the local socket path or nullptr if not applicable * (or if the path is corrupt). */ - gcc_pure + [[gnu::pure]] const char *GetLocalPath() const noexcept; #endif @@ -133,25 +132,25 @@ public: /** * Is this the IPv6 wildcard address (in6addr_any)? */ - gcc_pure + [[gnu::pure]] bool IsV6Any() const noexcept; /** * Is this an IPv4 address mapped inside struct sockaddr_in6? */ - gcc_pure + [[gnu::pure]] bool IsV4Mapped() const noexcept; /** * Convert "::ffff:127.0.0.1" to "127.0.0.1". */ - gcc_pure + [[gnu::pure]] IPv4Address UnmapV4() const noexcept; /** * Extract the port number. Returns 0 if not applicable. */ - gcc_pure + [[gnu::pure]] unsigned GetPort() const noexcept; #endif @@ -162,10 +161,10 @@ public: * much for anything else. Returns nullptr if the address is * not supported. */ - gcc_pure + [[gnu::pure]] ConstBuffer GetSteadyPart() const noexcept; - gcc_pure + [[gnu::pure]] bool operator==(const SocketAddress other) const noexcept; bool operator!=(const SocketAddress other) const noexcept { diff --git a/src/net/SocketDescriptor.hxx b/src/net/SocketDescriptor.hxx index 647c9bdd3..a69ab068e 100644 --- a/src/net/SocketDescriptor.hxx +++ b/src/net/SocketDescriptor.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 Max Kellermann + * Copyright 2012-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -90,13 +90,13 @@ public: * Determine the socket type, i.e. SOCK_STREAM, SOCK_DGRAM or * SOCK_SEQPACKET. Returns -1 on error. */ - gcc_pure + [[gnu::pure]] int GetType() const noexcept; /** * Is this a stream socket? */ - gcc_pure + [[gnu::pure]] bool IsStream() const noexcept; using FileDescriptor::Get; @@ -167,7 +167,7 @@ public: * Receive peer credentials (SO_PEERCRED). On error, the pid * is -1. */ - gcc_pure + [[gnu::pure]] struct ucred GetPeerCredentials() const noexcept; #endif @@ -226,10 +226,10 @@ public: bool Connect(SocketAddress address) noexcept; - gcc_pure + [[gnu::pure]] StaticSocketAddress GetLocalAddress() const noexcept; - gcc_pure + [[gnu::pure]] StaticSocketAddress GetPeerAddress() const noexcept; ssize_t Read(void *buffer, size_t length) noexcept; diff --git a/src/net/SocketError.hxx b/src/net/SocketError.hxx index 44989c52f..8a53c6f98 100644 --- a/src/net/SocketError.hxx +++ b/src/net/SocketError.hxx @@ -30,7 +30,6 @@ #ifndef SOCKET_ERROR_HXX #define SOCKET_ERROR_HXX -#include "util/Compiler.h" #include "system/Error.hxx" #ifdef _WIN32 @@ -41,7 +40,7 @@ typedef DWORD socket_error_t; typedef int socket_error_t; #endif -gcc_pure +[[gnu::pure]] static inline socket_error_t GetSocketError() noexcept { @@ -128,7 +127,7 @@ IsSocketErrorAcceptWouldBlock(socket_error_t code) noexcept #endif } -gcc_const +[[gnu::const]] static inline bool IsSocketErrorInterruped(socket_error_t code) noexcept { @@ -139,7 +138,7 @@ IsSocketErrorInterruped(socket_error_t code) noexcept #endif } -gcc_const +[[gnu::const]] static inline bool IsSocketErrorClosed(socket_error_t code) noexcept { @@ -171,7 +170,7 @@ public: } }; -gcc_const +[[gnu::const]] static inline std::system_error MakeSocketError(socket_error_t code, const char *msg) noexcept { @@ -182,7 +181,7 @@ MakeSocketError(socket_error_t code, const char *msg) noexcept #endif } -gcc_pure +[[gnu::pure]] static inline std::system_error MakeSocketError(const char *msg) noexcept { diff --git a/src/net/StaticSocketAddress.hxx b/src/net/StaticSocketAddress.hxx index 85c4e98b6..dc73e30e4 100644 --- a/src/net/StaticSocketAddress.hxx +++ b/src/net/StaticSocketAddress.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 Max Kellermann + * Copyright 2012-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,7 +32,6 @@ #include "SocketAddress.hxx" // IWYU pragma: export #include "Features.hxx" -#include "util/Compiler.h" #include @@ -120,7 +119,7 @@ public: /** * @see SocketAddress::GetLocalRaw() */ - gcc_pure + [[gnu::pure]] StringView GetLocalRaw() const noexcept; #endif @@ -128,7 +127,7 @@ public: /** * Extract the port number. Returns 0 if not applicable. */ - gcc_pure + [[gnu::pure]] unsigned GetPort() const noexcept { return ((SocketAddress)*this).GetPort(); } @@ -140,7 +139,7 @@ public: bool SetPort(unsigned port) noexcept; #endif - gcc_pure + [[gnu::pure]] bool operator==(SocketAddress other) const noexcept { return (SocketAddress)*this == other; } diff --git a/src/system/Error.hxx b/src/system/Error.hxx index ea2f31d69..289ceeaf8 100644 --- a/src/system/Error.hxx +++ b/src/system/Error.hxx @@ -30,8 +30,6 @@ #ifndef SYSTEM_ERROR_HXX #define SYSTEM_ERROR_HXX -#include "util/Compiler.h" - #include // IWYU pragma: export #include @@ -160,7 +158,7 @@ FormatFileNotFound(const char *fmt, Args&&... args) noexcept #endif } -gcc_pure +[[gnu::pure]] inline bool 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; } -gcc_pure +[[gnu::pure]] static inline bool IsFileNotFound(const std::system_error &e) noexcept { @@ -180,7 +178,7 @@ IsFileNotFound(const std::system_error &e) noexcept #endif } -gcc_pure +[[gnu::pure]] static inline bool IsPathNotFound(const std::system_error &e) noexcept { @@ -192,7 +190,7 @@ IsPathNotFound(const std::system_error &e) noexcept #endif } -gcc_pure +[[gnu::pure]] static inline bool IsAccessDenied(const std::system_error &e) noexcept { diff --git a/src/system/KernelVersion.cxx b/src/system/KernelVersion.cxx index 52da082cf..9b5403569 100644 --- a/src/system/KernelVersion.cxx +++ b/src/system/KernelVersion.cxx @@ -35,7 +35,7 @@ #include #include -gcc_const +[[gnu::const]] static KernelVersionCode GetKernelVersionCode() noexcept { diff --git a/src/system/KernelVersion.hxx b/src/system/KernelVersion.hxx index 51710787e..e3b591862 100644 --- a/src/system/KernelVersion.hxx +++ b/src/system/KernelVersion.hxx @@ -32,8 +32,6 @@ #pragma once -#include "util/Compiler.h" - class KernelVersionCode { unsigned value = 0; @@ -53,6 +51,6 @@ public: /** * Is the currently running Linux kernel at least the given version? */ -gcc_const +[[gnu::const]] bool IsKernelVersionOrNewer(KernelVersionCode v) noexcept; diff --git a/src/time/ClockCache.hxx b/src/time/ClockCache.hxx index b146ede37..a407749d1 100644 --- a/src/time/ClockCache.hxx +++ b/src/time/ClockCache.hxx @@ -47,7 +47,7 @@ public: ClockCache(const ClockCache &) = delete; ClockCache &operator=(const ClockCache &) = delete; - gcc_pure + [[gnu::pure]] const auto &now() const noexcept { if (value <= value_type()) value = Clock::now(); diff --git a/src/time/Convert.cxx b/src/time/Convert.cxx index 352c60604..53e5abaf8 100644 --- a/src/time/Convert.cxx +++ b/src/time/Convert.cxx @@ -72,7 +72,7 @@ LocalTime(std::chrono::system_clock::time_point tp) /** * Determine the time zone offset in a portable way. */ -gcc_const +[[gnu::const]] static time_t GetTimeZoneOffset() noexcept { diff --git a/src/time/Convert.hxx b/src/time/Convert.hxx index 2f6f3367a..113126472 100644 --- a/src/time/Convert.hxx +++ b/src/time/Convert.hxx @@ -33,8 +33,6 @@ #ifndef TIME_CONVERT_HXX #define TIME_CONVERT_HXX -#include "util/Compiler.h" - #include /** @@ -56,18 +54,18 @@ LocalTime(std::chrono::system_clock::time_point tp); /** * Convert a UTC-based "struct tm" to a UTC-based time point. */ -gcc_pure +[[gnu::pure]] std::chrono::system_clock::time_point TimeGm(struct tm &tm) noexcept; /** * Convert a local "struct tm" to a UTC-based time point. */ -gcc_pure +[[gnu::pure]] std::chrono::system_clock::time_point MakeTime(struct tm &tm) noexcept; -gcc_pure +[[gnu::pure]] std::chrono::steady_clock::duration ToSteadyClockDuration(const struct timeval &tv) noexcept; diff --git a/src/time/ISO8601.hxx b/src/time/ISO8601.hxx index 94633386d..2d271a318 100644 --- a/src/time/ISO8601.hxx +++ b/src/time/ISO8601.hxx @@ -33,8 +33,6 @@ #ifndef TIME_ISO8601_HXX #define TIME_ISO8601_HXX -#include "util/Compiler.h" - #include #include #include @@ -42,11 +40,11 @@ struct tm; template class StringBuffer; -gcc_pure +[[gnu::pure]] StringBuffer<64> FormatISO8601(const struct tm &tm) noexcept; -gcc_pure +[[gnu::pure]] StringBuffer<64> FormatISO8601(std::chrono::system_clock::time_point tp); diff --git a/src/time/Math.hxx b/src/time/Math.hxx index 891049947..947861a5b 100644 --- a/src/time/Math.hxx +++ b/src/time/Math.hxx @@ -32,8 +32,6 @@ #pragma once -#include "util/Compiler.h" - #include struct tm; @@ -42,7 +40,7 @@ struct tm; * Calculates the preceding midnight time point in the current time * zone. */ -gcc_const +[[gnu::const]] std::chrono::system_clock::time_point PrecedingMidnightLocal(std::chrono::system_clock::time_point t) noexcept;