mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Fix -Wmissing-prototypes warning on Clang. (#1863)
The -Wmissing-prototypes Clang warning (or -Wmissing-declarations on GCC) is very useful to avoid accidents where a function definition in a source file doesn't match the corresponding declaration in a header file, as it would warn already during compilation and not much later during link time. Unfortunately this means that exported functions defined only in the source file (usually the ones annotated with `extern "C"`) will cause this warning to be emitted too (on Clang, GCC has a slightly different behavior with -Wmissing-declarations and doesn't warn here). This fixes the warning by providing a declaration right before the definition.
This commit is contained in:
parent
5ef13eb680
commit
5b0ea77c62
@ -164,7 +164,9 @@
|
||||
#define PYBIND11_STR_TYPE ::pybind11::str
|
||||
#define PYBIND11_BOOL_ATTR "__bool__"
|
||||
#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
|
||||
// Providing a separate declaration to make Clang's -Wmissing-prototypes happy
|
||||
#define PYBIND11_PLUGIN_IMPL(name) \
|
||||
extern "C" PYBIND11_EXPORT PyObject *PyInit_##name(); \
|
||||
extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
|
||||
|
||||
#else
|
||||
@ -188,8 +190,10 @@
|
||||
#define PYBIND11_STR_TYPE ::pybind11::bytes
|
||||
#define PYBIND11_BOOL_ATTR "__nonzero__"
|
||||
#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_nonzero)
|
||||
// Providing a separate PyInit decl to make Clang's -Wmissing-prototypes happy
|
||||
#define PYBIND11_PLUGIN_IMPL(name) \
|
||||
static PyObject *pybind11_init_wrapper(); \
|
||||
extern "C" PYBIND11_EXPORT void init##name(); \
|
||||
extern "C" PYBIND11_EXPORT void init##name() { \
|
||||
(void)pybind11_init_wrapper(); \
|
||||
} \
|
||||
|
Loading…
Reference in New Issue
Block a user