diff --git a/src/main/cpp/asyncbuffer.cpp b/src/main/cpp/asyncbuffer.cpp index f42331223..a0b0711f2 100644 --- a/src/main/cpp/asyncbuffer.cpp +++ b/src/main/cpp/asyncbuffer.cpp @@ -17,9 +17,9 @@ #include #include -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts +#if LOG4CXX_CONCEPTS #include -#endif // defined(__cpp_concepts) && 202002 <= __cpp_concepts +#endif // LOG4CXX_CONCEPTS namespace LOG4CXX_NS { @@ -29,7 +29,7 @@ namespace helpers struct AsyncBuffer::Private { -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API +#if LOG4CXX_CONCEPTS && LOG4CXX_WCHAR_T_API using value_t = std::variant; #else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API) using value_t = MessageBufferAppender; @@ -135,7 +135,7 @@ void AsyncBuffer::renderMessage(LogCharMessageBuffer& msg) const if (m_priv) { for (auto& renderer : m_priv->data) -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API +#if LOG4CXX_CONCEPTS && LOG4CXX_WCHAR_T_API { #if LOG4CXX_LOGCHAR_IS_UTF8 if (auto pRenderer = std::get_if(&renderer)) @@ -159,9 +159,9 @@ void AsyncBuffer::renderMessage(LogCharMessageBuffer& msg) const } #endif // !LOG4CXX_LOGCHAR_IS_UTF8 } -#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API) +#else // !LOG4CXX_CONCEPTS renderer(msg); -#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API) +#endif // !LOG4CXX_CONCEPTS #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT #if LOG4CXX_LOGCHAR_IS_UTF8 @@ -206,7 +206,7 @@ void AsyncBuffer::clear() } } -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts +#if LOG4CXX_CONCEPTS /** * Append \c function to this buffer. */ @@ -230,7 +230,7 @@ void AsyncBuffer::append(const WideMessageBufferAppender& f) m_priv->data.push_back(f); } #endif // LOG4CXX_WCHAR_T_API -#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts +#else // !LOG4CXX_CONCEPTS /** * Append \c function to this buffer. */ @@ -241,7 +241,7 @@ void AsyncBuffer::append(const MessageBufferAppender& f) else m_priv->data.push_back(f); } -#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts +#endif // !LOG4CXX_CONCEPTS } // namespace helpers } // namespace LOG4CXX_NS diff --git a/src/main/include/log4cxx/helpers/asyncbuffer.h b/src/main/include/log4cxx/helpers/asyncbuffer.h index 1784b358c..7beb68944 100644 --- a/src/main/include/log4cxx/helpers/asyncbuffer.h +++ b/src/main/include/log4cxx/helpers/asyncbuffer.h @@ -27,7 +27,17 @@ #include #endif // LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR #endif // LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts + +#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && defined(__GNUC__) && __GNUC__ <= 12 +// GCC 12 has broken concepts +#define LOG4CXX_CONCEPTS 0 +#elif defined(__cpp_concepts) && 202002 <= __cpp_concepts +#define LOG4CXX_CONCEPTS 1 +#else +#define LOG4CXX_CONCEPTS 0 +#endif + +#if LOG4CXX_CONCEPTS #include #endif @@ -65,7 +75,7 @@ class LOG4CXX_EXPORT AsyncBuffer template AsyncBuffer& operator<<(const T& value) { -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts +#if LOG4CXX_CONCEPTS #if LOG4CXX_LOGCHAR_IS_UTF8 if constexpr (requires(std::ostream& buf, T v) { buf << v; }) { @@ -103,12 +113,12 @@ class LOG4CXX_EXPORT AsyncBuffer else static_assert(false, "operator<<(std::wostream&) overload must be provided"); #endif // !LOG4CXX_LOGCHAR_IS_UTF8 -#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts) +#else // !LOG4CXX_CONCEPTS append([value](LogCharMessageBuffer& msgBuf) { msgBuf << value; }); -#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts) +#endif // !LOG4CXX_CONCEPTS return *this; } @@ -120,7 +130,7 @@ class LOG4CXX_EXPORT AsyncBuffer template AsyncBuffer& operator<<(const T&& rvalue) { -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts +#if LOG4CXX_CONCEPTS #if LOG4CXX_LOGCHAR_IS_UTF8 if constexpr (requires(std::ostream& buf, T v) { buf << v; }) { @@ -158,12 +168,12 @@ class LOG4CXX_EXPORT AsyncBuffer else static_assert(false, "operator<<(std::wostream&) overload must be provided"); #endif // !LOG4CXX_LOGCHAR_IS_UTF8 -#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts) +#else // !LOG4CXX_CONCEPTS append([value = std::move(rvalue)](LogCharMessageBuffer& msgBuf) { msgBuf << value; }); -#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts) +#endif // !LOG4CXX_CONCEPTS return *this; } @@ -215,7 +225,7 @@ class LOG4CXX_EXPORT AsyncBuffer AsyncBuffer& operator=(const AsyncBuffer&) = delete; LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(Private, m_priv) -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts +#if LOG4CXX_CONCEPTS using MessageBufferAppender = std::function; /** @@ -231,14 +241,14 @@ class LOG4CXX_EXPORT AsyncBuffer */ void append(const WideMessageBufferAppender& f); #endif // LOG4CXX_WCHAR_T_API -#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts) +#else // !LOG4CXX_CONCEPTS using MessageBufferAppender = std::function; /** * Append \c f to this buffer. */ void append(const MessageBufferAppender& f); -#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts) +#endif // !LOG4CXX_CONCEPTS #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT void initializeForFmt(StringViewType&& format_string, FmtArgStore&& args); diff --git a/src/test/cpp/asyncappendertestcase.cpp b/src/test/cpp/asyncappendertestcase.cpp index 36744924f..871ce4a40 100644 --- a/src/test/cpp/asyncappendertestcase.cpp +++ b/src/test/cpp/asyncappendertestcase.cpp @@ -253,10 +253,10 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase #if !LOG4CXX_LOGCHAR_IS_UTF8 || LOG4CXX_WCHAR_T_API LOG4CXX_INFO(root, otherStr << 42); ++expectedEventCount; -#if defined(__cpp_concepts) && 202002 <= __cpp_concepts +#if LOG4CXX_CONCEPTS LOG4CXX_INFO_ASYNC(root, otherStr << 42); ++expectedEventCount; -#endif // defined(__cpp_concepts) && 202002 <= __cpp_concepts +#endif // LOG4CXX_CONCEPTS #endif // !LOG4CXX_LOGCHAR_IS_UTF8 || LOG4CXX_WCHAR_T_API // Check all messages were received