diff --git a/.jenkins.d/40-headers-check.sh b/.jenkins.d/40-headers-check.sh index 8ee33392..40e5f344 100755 --- a/.jenkins.d/40-headers-check.sh +++ b/.jenkins.d/40-headers-check.sh @@ -16,7 +16,7 @@ if [[ $ID_LIKE == *fedora* ]]; then fi CXX=${CXX:-g++} -STD=-std=c++14 +STD=-std=c++17 CXXFLAGS="-O2 -Wall -Wno-unneeded-internal-declaration -Wno-unused-const-variable $(pkg-config --cflags libndn-cxx $PCFILE)" INCLUDEDIR="$(pkg-config --variable=includedir $PCFILE)"/$PROJ diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py index 5f2d0b3b..8c718717 100644 --- a/.waf-tools/default-compiler-flags.py +++ b/.waf-tools/default-compiler-flags.py @@ -139,7 +139,7 @@ class GccBasicFlags(CompilerFlags): """ def getGeneralFlags(self, conf): flags = super(GccBasicFlags, self).getGeneralFlags(conf) - flags['CXXFLAGS'] += ['-std=c++14'] + flags['CXXFLAGS'] += ['-std=c++17'] if Utils.unversioned_sys_platform() != 'darwin': flags['LINKFLAGS'] += ['-fuse-ld=lld'] return flags diff --git a/README.md b/README.md index d4638b70..e01e4b33 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ [![CI](https://github.com/named-data/ndn-cxx/actions/workflows/ci.yml/badge.svg)](https://github.com/named-data/ndn-cxx/actions/workflows/ci.yml) [![Docs](https://github.com/named-data/ndn-cxx/actions/workflows/docs.yml/badge.svg)](https://github.com/named-data/ndn-cxx/actions/workflows/docs.yml) -![Language](https://img.shields.io/badge/C%2B%2B-14-blue) +![Language](https://img.shields.io/badge/C%2B%2B-17-blue) ![Latest version](https://img.shields.io/github/v/tag/named-data/ndn-cxx?label=Latest%20version) -**ndn-cxx** is a C++14 library implementing Named Data Networking (NDN) primitives +**ndn-cxx** is a C++17 library implementing Named Data Networking (NDN) primitives that can be used to write various NDN applications. The library is currently being used by the following projects: diff --git a/docs/code-style.rst b/docs/code-style.rst index 63bd327c..2baac21c 100644 --- a/docs/code-style.rst +++ b/docs/code-style.rst @@ -180,7 +180,7 @@ extended it to C++. switch (condition) { case ABC: // 2 space indent statements; // 4 space indent - NDN_CXX_FALLTHROUGH; + [[fallthrough]]; case DEF: statements; @@ -211,7 +211,7 @@ extended it to C++. // Correct style case A1: { statements; - NDN_CXX_FALLTHROUGH; + [[fallthrough]]; } // Incorrect style: braces should cover the entire case block @@ -232,7 +232,7 @@ extended it to C++. switch (condition) { case ABC: // no indent statements; // 2 space indent - NDN_CXX_FALLTHROUGH; + [[fallthrough]]; case DEF: statements; @@ -243,11 +243,11 @@ extended it to C++. break; } - The ``NDN_CXX_FALLTHROUGH`` annotation must be included whenever there is - a case without a break statement. Leaving the break out is a common error, + The ``[[fallthrough]]`` annotation must be included whenever there is a + case without a break statement. Leaving the break out is a common error, and it must be made clear that it is intentional when it is not there. - Moreover, modern compilers will warn when a case that falls through is not - explicitly annotated. + Moreover, modern compilers will warn when a case that falls through is + not explicitly annotated. 1.11. A ``try-catch`` statement should have the following form: diff --git a/docs/index.rst b/docs/index.rst index df9f0841..00943d5c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -19,7 +19,7 @@ ndn-cxx: NDN C++ library with eXperimental eXtensions release-notes releases -**ndn-cxx** is a C++14 library implementing Named Data Networking (NDN) primitives +**ndn-cxx** is a C++17 library implementing Named Data Networking (NDN) primitives that can be used to write various NDN applications. The library is currently being used by the following projects: diff --git a/ndn-cxx/detail/common.hpp b/ndn-cxx/detail/common.hpp index 13570c95..c64e4d8f 100644 --- a/ndn-cxx/detail/common.hpp +++ b/ndn-cxx/detail/common.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2021 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -30,9 +30,9 @@ #include "ndn-cxx/detail/config.hpp" -// require C++14 -#if __cplusplus < 201402L -#error "ndn-cxx applications must be compiled using the C++14 standard (-std=c++14)" +// require C++17 +#if __cplusplus < 201703L +#error "ndn-cxx applications must be compiled using the C++17 standard (-std=c++17)" #endif // ndn-cxx specific macros declared in this and other headers must have NDN_CXX_ prefix diff --git a/ndn-cxx/encoding/block.hpp b/ndn-cxx/encoding/block.hpp index 9f8a7728..b9439827 100644 --- a/ndn-cxx/encoding/block.hpp +++ b/ndn-cxx/encoding/block.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -162,7 +162,7 @@ public: // construction, assignment * @return `true` and the parsed Block if parsing succeeds; otherwise `false` and an invalid Block * @note This function does not throw upon decoding failure. */ - NDN_CXX_NODISCARD static std::tuple + [[nodiscard]] static std::tuple fromBuffer(ConstBufferPtr buffer, size_t offset = 0); /** @brief Try to parse Block from a byte range @@ -172,7 +172,7 @@ public: // construction, assignment * @note This overload copies the TLV element octets to an internal buffer. * @note This function does not throw upon decoding failure. */ - NDN_CXX_NODISCARD static std::tuple + [[nodiscard]] static std::tuple fromBuffer(span buffer); /** @brief Parse Block from an input stream diff --git a/ndn-cxx/encoding/tlv.hpp b/ndn-cxx/encoding/tlv.hpp index 176d6094..35a46e47 100644 --- a/ndn-cxx/encoding/tlv.hpp +++ b/ndn-cxx/encoding/tlv.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -176,7 +176,7 @@ isCriticalType(uint32_t type) noexcept * @return true if number was successfully read from input, false otherwise */ template -NDN_CXX_NODISCARD bool +[[nodiscard]] bool readVarNumber(Iterator& begin, Iterator end, uint64_t& number) noexcept; /** @@ -193,7 +193,7 @@ readVarNumber(Iterator& begin, Iterator end, uint64_t& number) noexcept; * the TLV-TYPE is zero or larger than 2^32-1 (maximum allowed by the packet format). */ template -NDN_CXX_NODISCARD bool +[[nodiscard]] bool readType(Iterator& begin, Iterator end, uint32_t& type) noexcept; /** diff --git a/ndn-cxx/impl/face-impl.hpp b/ndn-cxx/impl/face-impl.hpp index 239885da..86ccb9ed 100644 --- a/ndn-cxx/impl/face-impl.hpp +++ b/ndn-cxx/impl/face-impl.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -109,7 +109,7 @@ public: // consumer void asyncRemovePendingInterest(detail::RecordId id) { - m_face.getIoService().post([id, w = weak_ptr{shared_from_this()}] { // use weak_from_this() in C++17 + m_face.getIoService().post([id, w = weak_from_this()] { auto impl = w.lock(); if (impl != nullptr) { impl->m_pendingInterestTable.erase(id); @@ -195,7 +195,7 @@ public: // producer void asyncUnsetInterestFilter(detail::RecordId id) { - m_face.getIoService().post([id, w = weak_ptr{shared_from_this()}] { // use weak_from_this() in C++17 + m_face.getIoService().post([id, w = weak_from_this()] { auto impl = w.lock(); if (impl != nullptr) { impl->unsetInterestFilter(id); @@ -292,7 +292,7 @@ public: // prefix registration const UnregisterPrefixSuccessCallback& onSuccess, const UnregisterPrefixFailureCallback& onFailure) { - m_face.getIoService().post([=, w = weak_ptr{shared_from_this()}] { // use weak_from_this() in C++17 + m_face.getIoService().post([=, w = weak_from_this()] { auto impl = w.lock(); if (impl != nullptr) { impl->unregisterPrefix(id, onSuccess, onFailure); diff --git a/ndn-cxx/impl/record-container.hpp b/ndn-cxx/impl/record-container.hpp index e149b402..12fff0d1 100644 --- a/ndn-cxx/impl/record-container.hpp +++ b/ndn-cxx/impl/record-container.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2021 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -173,7 +173,7 @@ public: }); } - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const noexcept { return m_container.empty(); diff --git a/ndn-cxx/interest-filter.hpp b/ndn-cxx/interest-filter.hpp index 66d6cd2b..078ac1cf 100644 --- a/ndn-cxx/interest-filter.hpp +++ b/ndn-cxx/interest-filter.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -125,7 +125,7 @@ public: /** * \brief Get whether Interest loopback is allowed. */ - NDN_CXX_NODISCARD bool + [[nodiscard]] bool allowsLoopback() const noexcept { return m_allowsLoopback; diff --git a/ndn-cxx/interest.cpp b/ndn-cxx/interest.cpp index b6d8f3cd..345d60bf 100644 --- a/ndn-cxx/interest.cpp +++ b/ndn-cxx/interest.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -758,8 +758,7 @@ operator<<(std::ostream& os, const Interest& interest) auto printOne = [&] (const auto&... args) { os << delim; delim = '&'; - using expand = int[]; - (void)expand{(os << args, 0)...}; // use a fold expression when we switch to C++17 + (os << ... << args); }; if (interest.getCanBePrefix()) { diff --git a/ndn-cxx/interest.hpp b/ndn-cxx/interest.hpp index d2820523..9777c146 100644 --- a/ndn-cxx/interest.hpp +++ b/ndn-cxx/interest.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -464,7 +464,7 @@ private: Interest& setSignatureValueInternal(Block sigValue); - NDN_CXX_NODISCARD shared_ptr + [[nodiscard]] shared_ptr computeParametersDigest() const; /** @brief Append a ParametersSha256DigestComponent to the Interest's name diff --git a/ndn-cxx/key-locator.hpp b/ndn-cxx/key-locator.hpp index d12ac230..ec5688f0 100644 --- a/ndn-cxx/key-locator.hpp +++ b/ndn-cxx/key-locator.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -71,7 +71,7 @@ public: // encode and decode wireDecode(const Block& wire); public: // attributes - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const { return holds_alternative(m_locator); diff --git a/ndn-cxx/lp/packet.hpp b/ndn-cxx/lp/packet.hpp index 4febf548..5b905494 100644 --- a/ndn-cxx/lp/packet.hpp +++ b/ndn-cxx/lp/packet.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -61,7 +61,7 @@ public: * \retval true packet has no field * \retval false packet has one or more fields */ - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const { return m_wire.elements_size() == 0; @@ -73,7 +73,7 @@ public: // field access * \details This is equivalent to count() > 0 */ template - NDN_CXX_NODISCARD bool + [[nodiscard]] bool has() const { return count() > 0; @@ -83,7 +83,7 @@ public: // field access * \brief Returns the number of occurrences of \c FIELD. */ template - NDN_CXX_NODISCARD size_t + [[nodiscard]] size_t count() const { return std::count_if(m_wire.elements_begin(), m_wire.elements_end(), @@ -115,7 +115,7 @@ public: // field access * \brief Returns the values of all occurrences of \c FIELD. */ template - NDN_CXX_NODISCARD std::vector + [[nodiscard]] std::vector list() const { std::vector output; diff --git a/ndn-cxx/metadata-object.hpp b/ndn-cxx/metadata-object.hpp index 534b1fa1..6ad674af 100644 --- a/ndn-cxx/metadata-object.hpp +++ b/ndn-cxx/metadata-object.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2021 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -79,7 +79,7 @@ public: * * @throw tlv::Error @p discoveryInterestName is not valid */ - NDN_CXX_NODISCARD Data + [[nodiscard]] Data makeData(Name discoveryInterestName, KeyChain& keyChain, const ndn::security::SigningInfo& si = security::SigningInfo(), @@ -123,7 +123,7 @@ public: // static methods * * @param name prefix of data collection */ - NDN_CXX_NODISCARD static Interest + [[nodiscard]] static Interest makeDiscoveryInterest(Name name); private: diff --git a/ndn-cxx/name-component.hpp b/ndn-cxx/name-component.hpp index afd42a0b..9f196f23 100644 --- a/ndn-cxx/name-component.hpp +++ b/ndn-cxx/name-component.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -543,7 +543,7 @@ public: // commonly used TLV-TYPEs } public: // comparison - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const noexcept { return value_size() == 0; diff --git a/ndn-cxx/name.hpp b/ndn-cxx/name.hpp index 62066fc5..297c1efc 100644 --- a/ndn-cxx/name.hpp +++ b/ndn-cxx/name.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -142,7 +142,7 @@ public: // access /** * @brief Checks if the name is empty, i.e., has no components. */ - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const noexcept { return m_wire.elements().empty(); diff --git a/ndn-cxx/net/face-uri.hpp b/ndn-cxx/net/face-uri.hpp index 87555f45..bca98c93 100644 --- a/ndn-cxx/net/face-uri.hpp +++ b/ndn-cxx/net/face-uri.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California, + * Copyright (c) 2013-2023 Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -67,7 +67,7 @@ public: FaceUri(const char* uri); /// Exception-safe parsing. - NDN_CXX_NODISCARD bool + [[nodiscard]] bool parse(const std::string& uri); public: // scheme-specific construction diff --git a/ndn-cxx/net/network-monitor.hpp b/ndn-cxx/net/network-monitor.hpp index f9dcc8e1..3bd8927d 100644 --- a/ndn-cxx/net/network-monitor.hpp +++ b/ndn-cxx/net/network-monitor.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2021 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -92,7 +92,7 @@ public: * @warning May return incomplete results if called before the * #onEnumerationCompleted signal has been emitted. */ - NDN_CXX_NODISCARD std::vector> + [[nodiscard]] std::vector> listNetworkInterfaces() const; protected: diff --git a/ndn-cxx/security/impl/openssl-helper.hpp b/ndn-cxx/security/impl/openssl-helper.hpp index 310a2836..e3483919 100644 --- a/ndn-cxx/security/impl/openssl-helper.hpp +++ b/ndn-cxx/security/impl/openssl-helper.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -31,10 +31,10 @@ namespace ndn { namespace security { namespace detail { -NDN_CXX_NODISCARD const EVP_MD* +[[nodiscard]] const EVP_MD* digestAlgorithmToEvpMd(DigestAlgorithm algo); -NDN_CXX_NODISCARD int +[[nodiscard]] int getEvpPkeyType(const EVP_PKEY* key); class EvpMdCtx : noncopyable @@ -86,10 +86,10 @@ public: return m_bio; } - NDN_CXX_NODISCARD bool + [[nodiscard]] bool read(span buf) const noexcept; - NDN_CXX_NODISCARD bool + [[nodiscard]] bool write(span buf) noexcept; private: diff --git a/ndn-cxx/security/key-chain.cpp b/ndn-cxx/security/key-chain.cpp index bcedeb5d..dd30d730 100644 --- a/ndn-cxx/security/key-chain.cpp +++ b/ndn-cxx/security/key-chain.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -114,13 +114,13 @@ KeyChain::getDefaultKeyParams() class KeyChain::Locator { public: - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const { return scheme.empty(); } - NDN_CXX_NODISCARD std::string + [[nodiscard]] std::string canonical() const { return scheme + ':' + location; diff --git a/ndn-cxx/security/pib/certificate-container.hpp b/ndn-cxx/security/pib/certificate-container.hpp index 34f64880..52b4520d 100644 --- a/ndn-cxx/security/pib/certificate-container.hpp +++ b/ndn-cxx/security/pib/certificate-container.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -121,7 +121,7 @@ public: /** * @brief Check whether the container is empty. */ - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const noexcept { return m_certNames.empty(); diff --git a/ndn-cxx/security/pib/identity-container.hpp b/ndn-cxx/security/pib/identity-container.hpp index b354ade3..75fe3f40 100644 --- a/ndn-cxx/security/pib/identity-container.hpp +++ b/ndn-cxx/security/pib/identity-container.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -122,7 +122,7 @@ public: /** * @brief Check whether the container is empty. */ - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const noexcept { return m_identityNames.empty(); diff --git a/ndn-cxx/security/pib/key-container.hpp b/ndn-cxx/security/pib/key-container.hpp index 19ebfa9e..cb9b2113 100644 --- a/ndn-cxx/security/pib/key-container.hpp +++ b/ndn-cxx/security/pib/key-container.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -122,7 +122,7 @@ public: /** * @brief Check whether the container is empty. */ - NDN_CXX_NODISCARD bool + [[nodiscard]] bool empty() const noexcept { return m_keyNames.empty(); diff --git a/ndn-cxx/security/tpm/back-end.hpp b/ndn-cxx/security/tpm/back-end.hpp index 41078f2b..dfe50cda 100644 --- a/ndn-cxx/security/tpm/back-end.hpp +++ b/ndn-cxx/security/tpm/back-end.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2021 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -155,7 +155,7 @@ public: // key management * * @return True if the TPM was unlocked. */ - NDN_CXX_NODISCARD virtual bool + [[nodiscard]] virtual bool unlockTpm(const char* pw, size_t pwLen) const; protected: // helper methods diff --git a/ndn-cxx/security/tpm/tpm.hpp b/ndn-cxx/security/tpm/tpm.hpp index 4c239ed7..1ffdeb1e 100644 --- a/ndn-cxx/security/tpm/tpm.hpp +++ b/ndn-cxx/security/tpm/tpm.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -117,7 +117,7 @@ public: * @retval false the signature is not valid * @retval indeterminate the key does not exist */ - NDN_CXX_NODISCARD boost::logic::tribool + [[nodiscard]] boost::logic::tribool verify(const InputBuffers& bufs, span sig, const Name& keyName, DigestAlgorithm digestAlgorithm) const; @@ -156,7 +156,7 @@ public: // Management * @param password The password to unlock the TPM. * @param passwordLength The password size. */ - NDN_CXX_NODISCARD bool + [[nodiscard]] bool unlockTpm(const char* password, size_t passwordLength) const; NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // operations accessible only by KeyChain diff --git a/ndn-cxx/security/verification-helpers.hpp b/ndn-cxx/security/verification-helpers.hpp index 36cb7215..26cc824e 100644 --- a/ndn-cxx/security/verification-helpers.hpp +++ b/ndn-cxx/security/verification-helpers.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -51,21 +51,21 @@ class Certificate; /** * @brief Verify @p blobs using @p key against @p sig. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const InputBuffers& blobs, span sig, const transform::PublicKey& key); /** * @brief Verify @p blobs using @p key against @p sig. * @note @p key must be a public key in PKCS #8 format. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const InputBuffers& blobs, span sig, span key); /** * @brief Verify @p data using @p key. * @note @p key must be a public key in PKCS #8 format. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Data& data, span key); /** @@ -73,33 +73,33 @@ verifySignature(const Data& data, span key); * @note @p key must be a public key in PKCS #8 format. * @note This method verifies only signature of the signed interest. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Interest& interest, span key); /** * @brief Verify @p data using @p key. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Data& data, const transform::PublicKey& key); /** * @brief Verify @p interest using @p key. * @note This method verifies only signature of the signed interest. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Interest& interest, const transform::PublicKey& key); /** * @brief Verify @p data using @p key. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Data& data, const pib::Key& key); /** * @brief Verify @p interest using @p key. * @note This method verifies only signature of the signed interest. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Interest& interest, const pib::Key& key); /** @@ -107,7 +107,7 @@ verifySignature(const Interest& interest, const pib::Key& key); * * If @p cert is nullopt, @p data assumed to be self-verifiable (with digest or attributes) */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Data& data, const optional& cert); /** @@ -116,13 +116,13 @@ verifySignature(const Data& data, const optional& cert); * * If @p cert is nullptr, @p interest assumed to be self-verifiable (with digest or attributes) */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Interest& interest, const optional& cert); /** * @brief Verify @p data using @p tpm and @p keyName with the @p digestAlgorithm. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Data& data, const tpm::Tpm& tpm, const Name& keyName, DigestAlgorithm digestAlgorithm); @@ -130,7 +130,7 @@ verifySignature(const Data& data, const tpm::Tpm& tpm, const Name& keyName, * @brief Verify @p interest using @p tpm and @p keyName with the @p digestAlgorithm. * @note This method verifies only signature of the signed interest. */ -NDN_CXX_NODISCARD bool +[[nodiscard]] bool verifySignature(const Interest& interest, const tpm::Tpm& tpm, const Name& keyName, DigestAlgorithm digestAlgorithm); diff --git a/ndn-cxx/util/backports.hpp b/ndn-cxx/util/backports.hpp index 60151534..5a41294a 100644 --- a/ndn-cxx/util/backports.hpp +++ b/ndn-cxx/util/backports.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -28,50 +28,12 @@ #include #include -#ifdef __has_cpp_attribute -# define NDN_CXX_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#else -# define NDN_CXX_HAS_CPP_ATTRIBUTE(x) 0 -#endif - -#ifdef __has_include -# define NDN_CXX_HAS_INCLUDE(x) __has_include(x) -#else -# define NDN_CXX_HAS_INCLUDE(x) 0 -#endif - -// -// https://wg21.link/P0188 -// [[fallthrough]] attribute (C++17) -// -#if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(fallthrough) -# define NDN_CXX_FALLTHROUGH [[fallthrough]] -#elif NDN_CXX_HAS_CPP_ATTRIBUTE(clang::fallthrough) -# define NDN_CXX_FALLTHROUGH [[clang::fallthrough]] -#elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::fallthrough) -# define NDN_CXX_FALLTHROUGH [[gnu::fallthrough]] -#elif BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(7,0,0) -# define NDN_CXX_FALLTHROUGH __attribute__((fallthrough)) -#else -# define NDN_CXX_FALLTHROUGH ((void)0) -#endif - -// -// https://wg21.link/P0189 -// [[nodiscard]] attribute (C++17) -// -#if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(nodiscard) -# define NDN_CXX_NODISCARD [[nodiscard]] -#elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::warn_unused_result) -# define NDN_CXX_NODISCARD [[gnu::warn_unused_result]] -#else -# define NDN_CXX_NODISCARD -#endif - #ifndef NDN_CXX_HAVE_STD_TO_STRING #include #endif +#include + namespace ndn { // @@ -89,30 +51,6 @@ to_string(const T& val) } #endif // NDN_CXX_HAVE_STD_TO_STRING -// -// https://wg21.link/P0025 -// std::clamp() (C++17) -// -#if __cpp_lib_clamp >= 201603L -using std::clamp; -#else -template -constexpr const T& -clamp(const T& v, const T& lo, const T& hi, Compare comp) -{ - BOOST_ASSERT(!comp(hi, lo)); - return comp(v, lo) ? lo : comp(hi, v) ? hi : v; -} - -template -constexpr const T& -clamp(const T& v, const T& lo, const T& hi) -{ - BOOST_ASSERT(!(hi < lo)); - return (v < lo) ? lo : (hi < v) ? hi : v; -} -#endif // __cpp_lib_clamp - // // https://wg21.link/P1682 // std::to_underlying() (C++23) @@ -121,7 +59,7 @@ clamp(const T& v, const T& lo, const T& hi) using std::to_underlying; #else template -NDN_CXX_NODISCARD constexpr std::underlying_type_t +[[nodiscard]] constexpr std::underlying_type_t to_underlying(T val) noexcept { // instantiating underlying_type with a non-enum type is UB before C++20 diff --git a/ndn-cxx/util/logging.hpp b/ndn-cxx/util/logging.hpp index bdb0a890..644bf774 100644 --- a/ndn-cxx/util/logging.hpp +++ b/ndn-cxx/util/logging.hpp @@ -50,7 +50,7 @@ public: /** * \brief Get list of all registered logger names. */ - NDN_CXX_NODISCARD static std::set + [[nodiscard]] static std::set getLoggerNames(); /** \brief Set severity level. @@ -118,7 +118,7 @@ public: /** * \brief Create stream log destination using default formatting. */ - NDN_CXX_NODISCARD static boost::shared_ptr + [[nodiscard]] static boost::shared_ptr makeDefaultStreamDestination(shared_ptr os, bool wantAutoFlush = true); private: @@ -130,7 +130,7 @@ private: void registerLoggerNameImpl(std::string name); - NDN_CXX_NODISCARD std::set + [[nodiscard]] std::set getLoggerNamesImpl() const; /** diff --git a/ndn-cxx/util/ostream-joiner.hpp b/ndn-cxx/util/ostream-joiner.hpp index 85701022..e187854a 100644 --- a/ndn-cxx/util/ostream-joiner.hpp +++ b/ndn-cxx/util/ostream-joiner.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2021 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -19,17 +19,18 @@ * See AUTHORS.md for complete list of ndn-cxx authors and contributors. */ -/** \file - * \brief Backport of ostream_joiner from the Library Fundamentals v2 TS - * \sa https://en.cppreference.com/w/cpp/experimental/ostream_joiner +/** + * \file + * \brief Backport of `ostream_joiner` from the Library Fundamentals v2 TS + * \sa https://en.cppreference.com/w/cpp/experimental/ostream_joiner */ #ifndef NDN_CXX_UTIL_OSTREAM_JOINER_HPP #define NDN_CXX_UTIL_OSTREAM_JOINER_HPP -#include "ndn-cxx/util/backports.hpp" +#include "ndn-cxx/detail/common.hpp" -#if NDN_CXX_HAS_INCLUDE() +#if __has_include() # include # if __cpp_lib_experimental_ostream_joiner >= 201411 # define NDN_CXX_HAVE_EXPERIMENTAL_OSTREAM_JOINER diff --git a/ndn-cxx/util/regex/regex-top-matcher.cpp b/ndn-cxx/util/regex/regex-top-matcher.cpp index f326ca5e..0a334cea 100644 --- a/ndn-cxx/util/regex/regex-top-matcher.cpp +++ b/ndn-cxx/util/regex/regex-top-matcher.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2019 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -206,7 +206,7 @@ RegexTopMatcher::convertSpecialChar(const std::string& str) case '^': case '$': newStr.push_back('\\'); - NDN_CXX_FALLTHROUGH; + [[fallthrough]]; default: newStr.push_back(c); break; diff --git a/ndn-cxx/util/rtt-estimator.cpp b/ndn-cxx/util/rtt-estimator.cpp index a0a4779f..04310d2f 100644 --- a/ndn-cxx/util/rtt-estimator.cpp +++ b/ndn-cxx/util/rtt-estimator.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (C) 2016-2019, Arizona Board of Regents. + * Copyright (C) 2016-2023, Arizona Board of Regents. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -59,15 +59,15 @@ RttEstimator::addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples) beta * time::abs(m_sRtt - rtt)); m_sRtt = time::duration_cast((1 - alpha) * m_sRtt + alpha * rtt); } - m_rto = clamp(m_sRtt + m_options->k * m_rttVar, - m_options->minRto, m_options->maxRto); + m_rto = std::clamp(m_sRtt + m_options->k * m_rttVar, + m_options->minRto, m_options->maxRto); } void RttEstimator::backoffRto() { - m_rto = clamp(m_rto * m_options->rtoBackoffMultiplier, - m_options->minRto, m_options->maxRto); + m_rto = std::clamp(m_rto * m_options->rtoBackoffMultiplier, + m_options->minRto, m_options->maxRto); } void diff --git a/ndn-cxx/util/scheduler.cpp b/ndn-cxx/util/scheduler.cpp index 8a542c39..b8a96911 100644 --- a/ndn-cxx/util/scheduler.cpp +++ b/ndn-cxx/util/scheduler.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2020 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -37,7 +37,7 @@ public: { } - NDN_CXX_NODISCARD time::nanoseconds + [[nodiscard]] time::nanoseconds expiresFromNow() const { return std::max(expireTime - time::steady_clock::now(), 0_ns); diff --git a/ndn-cxx/util/segmenter.hpp b/ndn-cxx/util/segmenter.hpp index bfbf8387..8ebd1aa8 100644 --- a/ndn-cxx/util/segmenter.hpp +++ b/ndn-cxx/util/segmenter.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -50,7 +50,7 @@ public: * @param contentType The `ContentType` of created Data packets. * @note A minimum of one Data packet is always returned, even if @p buffer is empty. */ - NDN_CXX_NODISCARD std::vector> + [[nodiscard]] std::vector> segment(span buffer, const Name& dataName, size_t maxSegmentSize, @@ -66,7 +66,7 @@ public: * @param contentType The `ContentType` of created Data packets. * @note A minimum of one Data packet is always returned, even if @p input is empty. */ - NDN_CXX_NODISCARD std::vector> + [[nodiscard]] std::vector> segment(std::istream& input, const Name& dataName, size_t maxSegmentSize, diff --git a/ndn-cxx/util/string-helper.hpp b/ndn-cxx/util/string-helper.hpp index 11498379..4447df46 100644 --- a/ndn-cxx/util/string-helper.hpp +++ b/ndn-cxx/util/string-helper.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -99,7 +99,7 @@ private: * Each octet of input is always converted to two hex characters (e.g., "00" for octet==0). * The output string is a continuous sequence of hex characters without any whitespace separators. */ -NDN_CXX_NODISCARD std::string +[[nodiscard]] std::string toHex(span buffer, bool wantUpperCase = true); /** @@ -114,7 +114,7 @@ fromHex(const std::string& hexString); /** * @brief Convert (the least significant nibble of) @p n to the corresponding hex character. */ -NDN_CXX_NODISCARD constexpr char +[[nodiscard]] constexpr char toHexChar(unsigned int n, bool wantUpperCase = true) noexcept { return wantUpperCase ? @@ -125,7 +125,7 @@ toHexChar(unsigned int n, bool wantUpperCase = true) noexcept /** * @brief Convert the hex character @p c to an integer in [0, 15], or -1 if it's not a hex character. */ -NDN_CXX_NODISCARD constexpr int +[[nodiscard]] constexpr int fromHexChar(char c) noexcept { return (c >= '0' && c <= '9') ? int(c - '0') : @@ -151,7 +151,7 @@ fromHexChar(char c) noexcept * * @see RFC 3986 section 2 */ -NDN_CXX_NODISCARD std::string +[[nodiscard]] std::string escape(const std::string& str); void @@ -171,7 +171,7 @@ escape(std::ostream& os, const char* str, size_t len); * * @see RFC 3986 section 2 */ -NDN_CXX_NODISCARD std::string +[[nodiscard]] std::string unescape(const std::string& str); void diff --git a/tests/unit/security/pib/pib-data-fixture.hpp b/tests/unit/security/pib/pib-data-fixture.hpp index 66e7fbf0..64c86528 100644 --- a/tests/unit/security/pib/pib-data-fixture.hpp +++ b/tests/unit/security/pib/pib-data-fixture.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2022 Regents of the University of California. + * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -35,10 +35,10 @@ class PibDataFixture public: PibDataFixture(); - NDN_CXX_NODISCARD static shared_ptr + [[nodiscard]] static shared_ptr makePibWithIdentity(const Name& idName); - NDN_CXX_NODISCARD static shared_ptr + [[nodiscard]] static shared_ptr makePibWithKey(const Name& keyName, span key); public: diff --git a/tests/unit/util/backports.t.cpp b/tests/unit/util/backports.t.cpp deleted file mode 100644 index 2404d03f..00000000 --- a/tests/unit/util/backports.t.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2013-2020 Regents of the University of California. - * - * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). - * - * ndn-cxx library is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received copies of the GNU General Public License and GNU Lesser - * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see - * . - * - * See AUTHORS.md for complete list of ndn-cxx authors and contributors. - */ - -#include "ndn-cxx/util/backports.hpp" - -#include "tests/boost-test.hpp" - -namespace ndn { -namespace tests { - -BOOST_AUTO_TEST_SUITE(Util) -BOOST_AUTO_TEST_SUITE(TestBackports) - -BOOST_AUTO_TEST_CASE(Clamp) -{ - int x = clamp(5, 1, 10); - BOOST_CHECK_EQUAL(x, 5); - - x = clamp(-5, 1, 10); - BOOST_CHECK_EQUAL(x, 1); - - x = clamp(15, 1, 10); - BOOST_CHECK_EQUAL(x, 10); - - x = clamp(5, 10, 1, std::greater()); - BOOST_CHECK_EQUAL(x, 5); - - x = clamp(-5, 10, 1, std::greater()); - BOOST_CHECK_EQUAL(x, 1); - - x = clamp(15, 10, 1, std::greater()); - BOOST_CHECK_EQUAL(x, 10); -} - -BOOST_AUTO_TEST_SUITE_END() // TestBackports -BOOST_AUTO_TEST_SUITE_END() // Util - -} // namespace tests -} // namespace ndn