From 01aa190c38e89fd7d8bcb32ad9543e837ed354ff Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 13 Oct 2023 14:28:49 +0200 Subject: [PATCH] Do not use `[[nodiscard]]` attribute on compiler not supporting it. On aarch64, we use gcc version 6.3.0 which doesn't support the `[[nodiscard]]` attribute (see https://en.cppreference.com/w/cpp/compiler_support/17) So don't set the attribute if the attribute is not present. --- include/library.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/include/library.h b/include/library.h index f1a58f6c5..8ed86f324 100644 --- a/include/library.h +++ b/include/library.h @@ -186,6 +186,17 @@ class MultiKeyCache; using LibraryPtr = std::shared_ptr; using ConstLibraryPtr = std::shared_ptr; + +// Some compiler we use don't have [[nodiscard]] attribute. +// We don't want to declare `create` with it in this case. +#define LIBKIWIX_NODISCARD +#if defined __has_cpp_attribute + #if __has_cpp_attribute (nodiscard) + #undef LIBKIWIX_NODISCARD + #define LIBKIWIX_NODISCARD [[nodiscard]] + #endif +#endif + /** * A Library store several books. */ @@ -201,7 +212,7 @@ class Library: public std::enable_shared_from_this Library(); public: - [[nodiscard]] static LibraryPtr create() { + LIBKIWIX_NODISCARD static LibraryPtr create() { return LibraryPtr(new Library()); } ~Library(); @@ -408,6 +419,10 @@ class Library: public std::enable_shared_from_this std::unique_ptr m_bookDB; }; +// We don't need it anymore and we don't want to polute any other potential usage +// of `LIBKIWIX_NODISCARD` token. +#undef LIBKIWIX_NODISCARD + }