Skip to content

Commit 11f261b

Browse files
authored
Fix build under GCC 12 #563 (#566)
* Fix build under GCC 12 #563
1 parent 050c4cf commit 11f261b

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

src/main/cpp/asyncbuffer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#include <log4cxx/helpers/asyncbuffer.h>
1919
#include <log4cxx/helpers/transcoder.h>
20-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
20+
#if LOG4CXX_CONCEPTS
2121
#include <variant>
22-
#endif // defined(__cpp_concepts) && 202002 <= __cpp_concepts
22+
#endif // LOG4CXX_CONCEPTS
2323

2424
namespace LOG4CXX_NS
2525
{
@@ -29,7 +29,7 @@ namespace helpers
2929

3030
struct AsyncBuffer::Private
3131
{
32-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API
32+
#if LOG4CXX_CONCEPTS && LOG4CXX_WCHAR_T_API
3333
using value_t = std::variant<MessageBufferAppender, WideMessageBufferAppender>;
3434
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API)
3535
using value_t = MessageBufferAppender;
@@ -135,7 +135,7 @@ void AsyncBuffer::renderMessage(LogCharMessageBuffer& msg) const
135135
if (m_priv)
136136
{
137137
for (auto& renderer : m_priv->data)
138-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API
138+
#if LOG4CXX_CONCEPTS && LOG4CXX_WCHAR_T_API
139139
{
140140
#if LOG4CXX_LOGCHAR_IS_UTF8
141141
if (auto pRenderer = std::get_if<MessageBufferAppender>(&renderer))
@@ -159,9 +159,9 @@ void AsyncBuffer::renderMessage(LogCharMessageBuffer& msg) const
159159
}
160160
#endif // !LOG4CXX_LOGCHAR_IS_UTF8
161161
}
162-
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API)
162+
#else // !LOG4CXX_CONCEPTS
163163
renderer(msg);
164-
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API)
164+
#endif // !LOG4CXX_CONCEPTS
165165

166166
#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
167167
#if LOG4CXX_LOGCHAR_IS_UTF8
@@ -206,7 +206,7 @@ void AsyncBuffer::clear()
206206
}
207207
}
208208

209-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
209+
#if LOG4CXX_CONCEPTS
210210
/**
211211
* Append \c function to this buffer.
212212
*/
@@ -230,7 +230,7 @@ void AsyncBuffer::append(const WideMessageBufferAppender& f)
230230
m_priv->data.push_back(f);
231231
}
232232
#endif // LOG4CXX_WCHAR_T_API
233-
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts
233+
#else // !LOG4CXX_CONCEPTS
234234
/**
235235
* Append \c function to this buffer.
236236
*/
@@ -241,7 +241,7 @@ void AsyncBuffer::append(const MessageBufferAppender& f)
241241
else
242242
m_priv->data.push_back(f);
243243
}
244-
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts
244+
#endif // !LOG4CXX_CONCEPTS
245245

246246
} // namespace helpers
247247
} // namespace LOG4CXX_NS

src/main/include/log4cxx/helpers/asyncbuffer.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@
2727
#include <fmt/xchar.h>
2828
#endif // LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
2929
#endif // LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
30-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
30+
31+
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && defined(__GNUC__) && __GNUC__ <= 12
32+
// GCC 12 has broken concepts
33+
#define LOG4CXX_CONCEPTS 0
34+
#elif defined(__cpp_concepts) && 202002 <= __cpp_concepts
35+
#define LOG4CXX_CONCEPTS 1
36+
#else
37+
#define LOG4CXX_CONCEPTS 0
38+
#endif
39+
40+
#if LOG4CXX_CONCEPTS
3141
#include <concepts>
3242
#endif
3343

@@ -65,7 +75,7 @@ class LOG4CXX_EXPORT AsyncBuffer
6575
template <typename T>
6676
AsyncBuffer& operator<<(const T& value)
6777
{
68-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
78+
#if LOG4CXX_CONCEPTS
6979
#if LOG4CXX_LOGCHAR_IS_UTF8
7080
if constexpr (requires(std::ostream& buf, T v) { buf << v; })
7181
{
@@ -103,12 +113,12 @@ class LOG4CXX_EXPORT AsyncBuffer
103113
else
104114
static_assert(false, "operator<<(std::wostream&) overload must be provided");
105115
#endif // !LOG4CXX_LOGCHAR_IS_UTF8
106-
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
116+
#else // !LOG4CXX_CONCEPTS
107117
append([value](LogCharMessageBuffer& msgBuf)
108118
{
109119
msgBuf << value;
110120
});
111-
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
121+
#endif // !LOG4CXX_CONCEPTS
112122
return *this;
113123
}
114124

@@ -120,7 +130,7 @@ class LOG4CXX_EXPORT AsyncBuffer
120130
template <typename T>
121131
AsyncBuffer& operator<<(const T&& rvalue)
122132
{
123-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
133+
#if LOG4CXX_CONCEPTS
124134
#if LOG4CXX_LOGCHAR_IS_UTF8
125135
if constexpr (requires(std::ostream& buf, T v) { buf << v; })
126136
{
@@ -158,12 +168,12 @@ class LOG4CXX_EXPORT AsyncBuffer
158168
else
159169
static_assert(false, "operator<<(std::wostream&) overload must be provided");
160170
#endif // !LOG4CXX_LOGCHAR_IS_UTF8
161-
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
171+
#else // !LOG4CXX_CONCEPTS
162172
append([value = std::move(rvalue)](LogCharMessageBuffer& msgBuf)
163173
{
164174
msgBuf << value;
165175
});
166-
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
176+
#endif // !LOG4CXX_CONCEPTS
167177
return *this;
168178
}
169179

@@ -215,7 +225,7 @@ class LOG4CXX_EXPORT AsyncBuffer
215225
AsyncBuffer& operator=(const AsyncBuffer&) = delete;
216226

217227
LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(Private, m_priv)
218-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
228+
#if LOG4CXX_CONCEPTS
219229
using MessageBufferAppender = std::function<void(CharMessageBuffer&)>;
220230

221231
/**
@@ -231,14 +241,14 @@ class LOG4CXX_EXPORT AsyncBuffer
231241
*/
232242
void append(const WideMessageBufferAppender& f);
233243
#endif // LOG4CXX_WCHAR_T_API
234-
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
244+
#else // !LOG4CXX_CONCEPTS
235245
using MessageBufferAppender = std::function<void(LogCharMessageBuffer&)>;
236246

237247
/**
238248
* Append \c f to this buffer.
239249
*/
240250
void append(const MessageBufferAppender& f);
241-
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
251+
#endif // !LOG4CXX_CONCEPTS
242252

243253
#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
244254
void initializeForFmt(StringViewType&& format_string, FmtArgStore&& args);

src/test/cpp/asyncappendertestcase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
253253
#if !LOG4CXX_LOGCHAR_IS_UTF8 || LOG4CXX_WCHAR_T_API
254254
LOG4CXX_INFO(root, otherStr << 42);
255255
++expectedEventCount;
256-
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
256+
#if LOG4CXX_CONCEPTS
257257
LOG4CXX_INFO_ASYNC(root, otherStr << 42);
258258
++expectedEventCount;
259-
#endif // defined(__cpp_concepts) && 202002 <= __cpp_concepts
259+
#endif // LOG4CXX_CONCEPTS
260260
#endif // !LOG4CXX_LOGCHAR_IS_UTF8 || LOG4CXX_WCHAR_T_API
261261

262262
// Check all messages were received

0 commit comments

Comments
 (0)