switch statement case label has only `int` template argument
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by locating the switch_statement and case_statement entry points named in the report, then reproduce the sample with the stated compiler behavior. Trace how the case value and lambda argument are typed; done means an integral case value such as 2147483648 is represented and matched correctly instead of producing “other,” with regression coverage for the behavior.
Written by the indexing model from the issue text.
Description
Before gcc9, if a template argument is an integral value, no compiler error/warning generated when the specified value is bigger than the integral value MAX.
This leads the following runtime issue:
#include <iostream>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/switch.hpp>
int main() {
using namespace boost;
using namespace boost::lambda;
switch_statement(
_1,
case_statement<2147483648>(std::cout << constant("big")),
default_statement(std::cout << constant("other"))
)(2147483648); // prints 'other'
// static_cast<int>(2147483648) is OK
}
This issue prone working can be eliminated in any following way:
- replace case_statement template argument from
inttouintmax_torintmax_tor any bigger than int. This solves that not onlyintparameters can be accepted in later gcc's and clang too. - switch_statement lambda accepts/casts argument
int. This solves type safety. - some other template magic, where at case statement can be set the acceptable integral type, and switch statement recognizes, and uses
common_typeto casts lambda parameter to that.
- Dominant language
- C++
- Stars
- 20
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
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.
More from boostorg/lambda
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·