pybind / pybind/pybind11

[BUG]: Warning on MSVC when defining functions that accept raw function pointers

Open
#3,415 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.