Pybind11: "no matching function for call to 'operator delete'" in projected targeting C++17, Clang 7.0

Created on 10 Nov 2018  路  10Comments  路  Source: pybind/pybind11

Issue description

Build targeting C++17 with Clang version 7.0 fails with error:

error: no matching function for call to 'operator delete' ::operator delete(p,s,std::align_val_t(a));

note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'ImNewDummy' for 2nd argument
inline void operator delete(void, ImNewDummy, void)

replacing operator delete(p, s, std::align_val_t(a)) with operator delete(p) solves the build issue

Most helpful comment

Hi,
I think I solved this problem by enabling sized deallocation under Clang, which is not enabled by default (see https://bcain-llvm.readthedocs.io/projects/clang/en/release_37/ReleaseNotes/).

Use the option -fsized-deallocation. The macro __cpp_sized_deallocation should then be defined in the C++ header "new", and the operator delete with signature void operator delete(void*, std::size_t, std::align_val_t) will be declared.

All 10 comments

Looks like you are working with a class that defines a custom deletion operator. We'll need a minimal self-contained example before this issue can be discussed in more detail.

I can reproduce this by compiling the pybind11 repo in C++17 mode (running clang 7.0 on archlinux):

cmake -DCMAKE_CXX_COMPILER=clang++ -DPYBIND11_CPP_STANDARD=-std=c++17 ..

Hi,
I think I solved this problem by enabling sized deallocation under Clang, which is not enabled by default (see https://bcain-llvm.readthedocs.io/projects/clang/en/release_37/ReleaseNotes/).

Use the option -fsized-deallocation. The macro __cpp_sized_deallocation should then be defined in the C++ header "new", and the operator delete with signature void operator delete(void*, std::size_t, std::align_val_t) will be declared.

Use the option -fsized-deallocation.

Fixes it for me as well. Anyone know a cross-platform (cmake) way to check when this should be added?

I ran into this too. It might make sense to detect this (Clang/C++17)
in the pybind cmake and add -fsized-deallocation to the interface since pybind explicitly is invoking sized deallocation. More background on Clang: https://reviews.llvm.org/D8467

@NikolausDemmel I just did something like

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    target_compile_options(pybind11 INTERFACE -fsized-deallocation)
endif()

There's a chance that my RobotLocomotion/pybind11#30 has resolved the problem. (You are welcome to cherry-pick it here upstream, if you like.)

I ran into this problem when compiling the first example in the documentation with clang:

#include <pybind11/pybind11.h>

int add(int i, int j) {
    return i + j;
}

PYBIND11_MODULE(example, m) {
    m.doc() = "pybind11 example plugin"; // optional module docstring

    m.def("add", &add, "A function which adds two numbers");
}

Indeed it works with -fsized-deallocation.

Should this be closed now?

(@wjakob cherry-picked a fix in 759221f5c56939f59d8f342a41f8e2d2cacbc8cf - maybe a 2.4.4 could be released so it's fixed in stable?)

The issue looks solved. Should it be closed?

Indeed, closing.

Was this page helpful?
0 / 5 - 0 ratings