2020#include < cassert>
2121#include < cstring>
2222#include < exception>
23+ #include < memory>
2324#include < stdexcept>
2425#include < string>
2526#include < type_traits>
@@ -54,7 +55,7 @@ class udf_base {
5455 static const char *get_function_label (std::string &buffer,
5556 const char *meta_name,
5657 item_result_type item_result) noexcept {
57- const char *res = " <function_name> " ;
58+ const char *res{ nullptr } ;
5859 try {
5960 buffer = meta_name;
6061 buffer += ' <' ;
@@ -63,6 +64,7 @@ class udf_base {
6364 buffer += ' >' ;
6465 res = buffer.c_str ();
6566 } catch (...) {
67+ res = " <function_name>" ;
6668 }
6769 return res;
6870 }
@@ -72,20 +74,11 @@ class udf_base {
7274 assert (error_reporter != nullptr );
7375 std::string buffer;
7476 try {
75- // The following suppression is needed exclusively for Clang 5.0 that
76- // has a bug in noexcept specification diagnostics.
77- #if defined(__clang__) && (__clang_major__ == 5)
78- #pragma clang diagnostic push
79- #pragma clang diagnostic ignored "-Wexceptions"
80- #endif
8177 // Rethrowing the exception that was previously caught with
8278 // 'catch(...)' in one of the derived classes
8379 // This is done to write the sequence of the catch blocks
8480 // in one place.
8581 throw ;
86- #if defined(__clang__) && (__clang_major__ == 5)
87- #pragma clang diagnostic pop
88- #endif
8982 } catch (const udf_exception &e) {
9083 if (e.has_error_code ()) {
9184 auto error_code = e.get_error_code ();
@@ -116,20 +109,11 @@ class udf_base {
116109 static void handle_init_exception (char *message,
117110 std::size_t message_size) noexcept {
118111 try {
119- // The following suppression is needed exclusively for Clang 5.0 that
120- // has a bug in noexcept specification diagnostics
121- #if defined(__clang__) && (__clang_major__ == 5)
122- #pragma clang diagnostic push
123- #pragma clang diagnostic ignored "-Wexceptions"
124- #endif
125112 // Rethrowing the exception that was previously caught with
126113 // 'catch(...)' in one of the derived classes
127114 // This is done to write the sequence of the catch blocks
128115 // in one place.
129116 throw ;
130- #if defined(__clang__) && (__clang_major__ == 5)
131- #pragma clang diagnostic pop
132- #endif
133117 } catch (const std::exception &e) {
134118 std::strncpy (message, e.what (), message_size);
135119 message[message_size - 1 ] = ' \0 ' ;
@@ -155,18 +139,21 @@ class generic_udf_base : private udf_base {
155139 udf_context udf_ctx{initid, args};
156140 extended_impl_t *impl = nullptr ;
157141 try {
142+ // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
158143 impl = new extended_impl_t {udf_ctx};
159144 } catch (...) {
160145 handle_init_exception (message, MYSQL_ERRMSG_SIZE);
161146 return true ;
162147 }
163148
149+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
164150 initid->ptr = reinterpret_cast <char *>(impl);
165151
166152 return false ;
167153 }
168154
169155 static void deinit (UDF_INIT *initid) noexcept {
156+ // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
170157 delete get_extended_impl_from_udf_initid (initid);
171158 }
172159
@@ -175,6 +162,7 @@ class generic_udf_base : private udf_base {
175162
176163 static extended_impl_t *get_extended_impl_from_udf_initid (
177164 UDF_INIT *initid) noexcept {
165+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
178166 return reinterpret_cast <extended_impl_t *>(initid->ptr );
179167 }
180168};
@@ -207,12 +195,11 @@ class generic_udf<ImplType, STRING_RESULT>
207195 assert (udf_ctx.is_result_nullabale ());
208196 *is_null = 1 ;
209197 return nullptr ;
210- } else {
211- *is_null = 0 ;
212- extended_impl.mixin = std::move (res.value ());
213- *length = extended_impl.mixin .size ();
214- return const_cast <char *>(extended_impl.mixin .c_str ());
215198 }
199+ *is_null = 0 ;
200+ extended_impl.mixin = std::move (*res);
201+ *length = extended_impl.mixin .size ();
202+ return const_cast <char *>(extended_impl.mixin .c_str ());
216203 }
217204};
218205
@@ -240,10 +227,9 @@ class generic_udf<ImplType, REAL_RESULT>
240227 assert (udf_ctx.is_result_nullabale ());
241228 *is_null = 1 ;
242229 return 0.0 ;
243- } else {
244- *is_null = 0 ;
245- return res.value ();
246230 }
231+ *is_null = 0 ;
232+ return *res;
247233 }
248234};
249235
@@ -271,15 +257,15 @@ class generic_udf<ImplType, INT_RESULT>
271257 assert (udf_ctx.is_result_nullabale ());
272258 *is_null = 1 ;
273259 return 0 ;
274- } else {
275- *is_null = 0 ;
276- return res.value ();
277260 }
261+ *is_null = 0 ;
262+ return *res;
278263 }
279264};
280265
281266} // namespace mysqlpp
282267
268+ // NOLINTBEGIN(cppcoreguidelines-macro-usage)
283269#define DECLARE_UDF_META_INFO (IMPL, RESULT_TYPE, NAME ) \
284270 namespace mysqlpp { \
285271 template <> \
@@ -290,40 +276,44 @@ class generic_udf<ImplType, INT_RESULT>
290276 }; \
291277 }
292278
293- #define DECLARE_UDF_INIT (IMPL, RESULT_TYPE, NAME ) \
294- MYSQLPP_UDF_EXPORT \
295- bool NAME##_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { \
296- static_assert (std::is_same_v<decltype (&NAME##_init), Udf_func_init>, \
297- " Invalid UDF init function signature" ); \
298- return mysqlpp::generic_udf<IMPL, RESULT_TYPE>::init (initid, args, \
299- message); \
279+ #define DECLARE_UDF_INIT (IMPL, RESULT_TYPE, NAME ) \
280+ MYSQLPP_UDF_EXPORT \
281+ bool NAME##_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { \
282+ static_assert ( \
283+ std::is_same_v<decltype (std::addressof (NAME##_init)), Udf_func_init>, \
284+ " Invalid UDF init function signature" ); \
285+ return mysqlpp::generic_udf<IMPL, RESULT_TYPE>::init (initid, args, \
286+ message); \
300287 }
301288
302- #define DECLARE_UDF_DEINIT (IMPL, RESULT_TYPE, NAME ) \
303- MYSQLPP_UDF_EXPORT \
304- void NAME##_deinit(UDF_INIT *initid) { \
305- static_assert (std::is_same_v<decltype (&NAME##_deinit), Udf_func_deinit>, \
306- " Invalid UDF deinit function signature" ); \
307- mysqlpp::generic_udf<IMPL, RESULT_TYPE>::deinit (initid); \
289+ #define DECLARE_UDF_DEINIT (IMPL, RESULT_TYPE, NAME ) \
290+ MYSQLPP_UDF_EXPORT \
291+ void NAME##_deinit(UDF_INIT *initid) { \
292+ static_assert (std::is_same_v<decltype (std::addressof (NAME##_deinit)), \
293+ Udf_func_deinit>, \
294+ " Invalid UDF deinit function signature" ); \
295+ mysqlpp::generic_udf<IMPL, RESULT_TYPE>::deinit (initid); \
308296 }
309297
310- #define DECLARE_UDF_STRING_FUNC (IMPL, NAME ) \
311- MYSQLPP_UDF_EXPORT \
312- char *NAME (UDF_INIT *initid, UDF_ARGS *args, char *result, \
313- unsigned long *length, unsigned char *is_null, \
314- unsigned char *error) { \
315- static_assert (std::is_same_v<decltype (&NAME), Udf_func_string>, \
316- " Invalid string UDF function signature" ); \
317- return mysqlpp::generic_udf<IMPL, STRING_RESULT>::func ( \
318- initid, args, result, length, is_null, error); \
298+ #define DECLARE_UDF_STRING_FUNC (IMPL, NAME ) \
299+ MYSQLPP_UDF_EXPORT \
300+ char *NAME (UDF_INIT *initid, UDF_ARGS *args, char *result, \
301+ unsigned long *length, unsigned char *is_null, \
302+ unsigned char *error) { \
303+ static_assert ( \
304+ std::is_same_v<decltype (std::addressof (NAME)), Udf_func_string>, \
305+ " Invalid string UDF function signature" ); \
306+ return mysqlpp::generic_udf<IMPL, STRING_RESULT>::func ( \
307+ initid, args, result, length, is_null, error); \
319308 }
320309
321310#define DECLARE_UDF_REAL_FUNC (IMPL, NAME ) \
322311 MYSQLPP_UDF_EXPORT \
323312 double NAME (UDF_INIT *initid, UDF_ARGS *args, unsigned char *is_null, \
324313 unsigned char *error) { \
325- static_assert (std::is_same_v<decltype (&NAME), Udf_func_double>, \
326- " Invalid real UDF function signature" ); \
314+ static_assert ( \
315+ std::is_same_v<decltype (std::addressof (NAME)), Udf_func_double>, \
316+ " Invalid real UDF function signature" ); \
327317 return mysqlpp::generic_udf<IMPL, REAL_RESULT>::func (initid, args, \
328318 is_null, error); \
329319 }
@@ -332,7 +322,8 @@ class generic_udf<ImplType, INT_RESULT>
332322 MYSQLPP_UDF_EXPORT \
333323 long long NAME (UDF_INIT *initid, UDF_ARGS *args, unsigned char *is_null, \
334324 unsigned char *error) { \
335- static_assert (std::is_same<decltype (&NAME), Udf_func_longlong>::value, \
325+ static_assert (std::is_same<decltype (std::addressof (NAME)), \
326+ Udf_func_longlong>::value, \
336327 " Invalid int UDF function signature" ); \
337328 return mysqlpp::generic_udf<IMPL, INT_RESULT>::func (initid, args, is_null, \
338329 error); \
@@ -363,4 +354,6 @@ class generic_udf<ImplType, INT_RESULT>
363354#define DECLARE_REAL_UDF_AUTO (NAME ) DECLARE_REAL_UDF(NAME##_impl, NAME)
364355#define DECLARE_INT_UDF_AUTO (NAME ) DECLARE_INT_UDF(NAME##_impl, NAME)
365356
357+ // NOLINTEND(cppcoreguidelines-macro-usage)
358+
366359#endif
0 commit comments