rust-lang / rust-lang/rust-bindgen
bindgen disregards c++ using directives.
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Input C/C++ Header
#include <compare>, found in gcc 10.0+, see link:
namespace std _GLIBCXX_VISIBILITY(default)
{
// [cmp.categories], comparison category types
namespace __cmp_cat
{
using type = signed char;
enum class _Ord : type { equivalent = 0, less = -1, greater = 1 };
enum class _Ncmp : type { _Unordered = 2 };
struct __unspec
{
constexpr __unspec(__unspec*) noexcept { }
};
}
// snip
}
Bindgen Invocation
bindgen flags:
opaque_types = [
"std::.*",
],
bindgen output:
pub mod __cmp_cat {
#[allow(unused_imports)]
use self::super::super::super::root;
pub type type_ = u8;
pub const _Ord_equivalent: root::std::__cmp_cat::_Ord = 0;
pub const _Ord_less: root::std::__cmp_cat::_Ord = -1;
pub const _Ord_greater: root::std::__cmp_cat::_Ord = 1;
pub type _Ord = root::std::__cmp_cat::type_;
pub const _Ncmp__Unordered: root::std::__cmp_cat::_Ncmp = 2;
pub type _Ncmp = root::std::__cmp_cat::type_;
#[repr(C)]
#[repr(align(1))]
#[derive(Debug, Copy, Clone)]
pub struct __unspec {
pub _bindgen_opaque_blob: u8,
}
}
Actual Results
error[E0600]: cannot apply unary operator `-` to type `u8`
--> xxx/lib.rs:1763:63
|
1763 | pub const _Ord_less: root::std::__cmp_cat::_Ord = -1;
| ^^
| |
| cannot apply unary operator `-`
| help: you may have meant the maximum value of `u8`: `u8::MAX`
|
= note: unsigned values cannot be negated
Expected Results
Bindgen should use pub tye type_ = i8 (instead of u8), because c++ has: using type = signed char;, hence the code should compile.
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 by reproducing the provided C++ header and bindgen configuration, then trace how the using type = signed char alias is translated into the generated Rust type. Add a regression test if the repository has a suitable bindgen test location; done means the alias becomes i8 and the negative _Ord_less constant compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100