[BUG]: Warning on MSVC when defining functions that accept raw function pointers
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
Problem description
I have a C function that I'm binding to Python that excepts a raw function pointer. On MSVC I get warning 4180 when compiling.
I'm pretty sure that raw function pointers aren't supported, but it should probably give either an error or do nothing, not a warning.
Compile the example code with something like:
cl /nologo -IC:\python\include -IC:\py\git\pybind11\include /EHsc /Febug.pyd /LD /MDd C:\python\libs\python39.lib
Reproducible example code
#include "pybind11/pybind11.h"
using namespace pybind11;
typedef int (* callback)(int a, int b);
int add_with_callback(callback callback, int a, int b) {
return callback(a, b);
}
PYBIND11_MODULE(bug, m) {
m.def("add_with_callback", &add_with_callback);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducible C++ example and the provided MSVC command, then trace the binding path reached by m.def for a raw function pointer. Determine whether the supported outcome is warning-free handling or an explicit error; done means rebuilding the example produces that deliberate outcome without warning 4180.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100