Compile error with clang, pybind 2.3.0, C++17
I don't know if this is a clang bug or a pybind bug (or something else :smile:)
Ubuntu 16.04
Clang 8.01
stdlib is libstdc++.so.6.0.26, from GCC 9
Example:
pybind-fail.cc
#include <pybind11/pybind11.h>
int main() {}
compile with clang++ -std=c++1z test.cc -I <python-libs>
Gives:
In file included from pybind-fail.cc:1:
/home/tom/Downloads/pybind11-2.3.0/include/pybind11/pybind11.h:1009:9: error: no matching function for call to 'operator delete'
::operator delete(p, s, std::align_val_t(a));
^~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:154:6: note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'std::align_val_t' for 2nd argument
void operator delete(void*, std::align_val_t, const std::nothrow_t&)
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:152:6: note: candidate function not viable: requires 2 arguments, but 3 were provided
void operator delete(void*, std::align_val_t)
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:143:6: note: candidate function not viable: requires 2 arguments, but 3 were provided
void operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:179:13: note: candidate function not viable: requires 2 arguments, but 3 were provided
inline void operator delete (void*, void*) _GLIBCXX_USE_NOEXCEPT { }
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:129:6: note: candidate function not viable: requires 1 argument, but 3 were provided
void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
^
In file included from pybind-fail.cc:1:
/home/tom/Downloads/pybind11-2.3.0/include/pybind11/pybind11.h:1011:9: error: no matching function for call to 'operator delete'
::operator delete(p, s);
^~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:179:13: note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'void *' for 2nd argument; take the address of the argument with &
inline void operator delete (void*, void*) _GLIBCXX_USE_NOEXCEPT { }
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:143:6: note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'const std::nothrow_t' for 2nd argument
void operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:152:6: note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'std::align_val_t' for 2nd argument
void operator delete(void*, std::align_val_t)
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:129:6: note: candidate function not viable: requires 1 argument, but 2 were provided
void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:154:6: note: candidate function not viable: requires 3 arguments, but 2 were provided
void operator delete(void*, std::align_val_t, const std::nothrow_t&)
^
2 errors generated.
PS, thanks for your work on this library. It's awesome :+1: :
Probably an outdated libstdc++ that doesn't have the C++17 aligned new. You could either update libstdc++, use LLVM's libc++, or revert to C++14.
Maybe, but GCC seems to handle it fine. I'll look into the libstdc++ version tomorrow. Thank you.
So the issue here is clang does not, by default, define __cpp_sized_deallocation which libstdc++ uses to control whether the overload pybind11 is looking for exists. GCC does define this, and one can force clang to with -fsized-deallocation. I don't quite know the consequences of the flag, but it's good enough to get your latest release going :+1:
here's an llvm thread on this: https://reviews.llvm.org/D8467
Most helpful comment
So the issue here is clang does not, by default, define
__cpp_sized_deallocationwhich libstdc++ uses to control whether the overload pybind11 is looking for exists. GCC does define this, and one can force clang to with-fsized-deallocation. I don't quite know the consequences of the flag, but it's good enough to get your latest release going :+1:here's an llvm thread on this: https://reviews.llvm.org/D8467