diff options
author | Jani Nikula <jani@nikula.org> | 2012-04-12 23:57:39 +0300 |
---|---|---|
committer | David Bremner <bremner@debian.org> | 2012-04-15 09:42:15 -0300 |
commit | de0557477d908be26615e8fda9f5eb62bed68b65 (patch) | |
tree | c71bba24b66206834edf7623019ef0f118de32f1 /lib | |
parent | cddc27034687e1c3bc52204314dfa46219b5d6f9 (diff) |
lib: work around talloc_steal usage from C++ code
Implicit typecast from 'void *' to 'T *' is okay in C, but not in
C++. In talloc_steal, an explicit cast is provided for type safety in
some GCC versions. Otherwise, a cast is required. Provide a template
function for this to maintain type safety, and redefine talloc_steal
to use it.
The template must be outside the extern "C" block (NOTMUCH_BEGIN_DECLS
and NOTMUCH_END_DECLS), but keep it within the GCC visibility #pragma.
No functional changes, apart from making the library build with
compilers other than recent GCC.
Signed-off-by: Jani Nikula <jani@nikula.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/notmuch-private.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index ea836f72..3886e0ca 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -495,8 +495,26 @@ notmuch_filenames_t * _notmuch_filenames_create (const void *ctx, notmuch_string_list_t *list); -#pragma GCC visibility pop - NOTMUCH_END_DECLS +#ifdef __cplusplus +/* Implicit typecast from 'void *' to 'T *' is okay in C, but not in + * C++. In talloc_steal, an explicit cast is provided for type safety + * in some GCC versions. Otherwise, a cast is required. Provide a + * template function for this to maintain type safety, and redefine + * talloc_steal to use it. + */ +#if !(__GNUC__ >= 3) +template <class T> T * +_notmuch_talloc_steal (const void *new_ctx, const T *ptr) +{ + return static_cast<T *> (talloc_steal (new_ctx, ptr)); +} +#undef talloc_steal +#define talloc_steal _notmuch_talloc_steal +#endif +#endif + +#pragma GCC visibility pop + #endif |