[BUG]: Description of is_fmt_numeric does not match actual behavior
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.
What version (or hash if on master) of pybind11 are you using?
75e48c5f959b4f0a49d8c664e059b6fb4b497102
Problem description
The description of is_fmt_numeric states (in comments):
Note that the long double types only participate when long double is actually longer than double (it isn't under MSVC).
However this isn't what actually happens, because std::is_same<double, long double>::value is false even when sizeof(double) == sizeof(long double), as is indeed the case with MSVC on x86_64:
https://godbolt.org/z/xdd135a8T
Likewise, std::is_same<int, long>::value is false even when sizeof(int) == sizeof(long). This is presumably why platform_lookup uses sizeof rather than std::is_same to check type equivalence.
I'm not sure whether the correct solution here is to update the description to match actual behavior, or rather change the behavior to match the description.
Reproducible example code
int main() {
std::cerr << sizeof(float) << ' ' << detail::is_fmt_numeric<float>::index << std::endl;
std::cerr << sizeof(double) << ' ' << detail::is_fmt_numeric<double>::index << std::endl;
std::cerr << sizeof(long double) << ' ' << detail::is_fmt_numeric<long double>::index << std::endl;
};
// expected output:
// 4 9
// 8 10
// 8 10
// actual output:
// 4 9
// 8 10
// 8 11
Is this a regression? Put the last known working version here if it is.
Not a regression
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 is_fmt_numeric description and implementation, then compare its type checks with platform_lookup, which the report identifies as using sizeof. Reproduce the float, double, and long double indices from the example on MSVC or the linked Compiler Explorer case, and resolve whether the implementation or comment should change with coverage for the intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100