boostorg / boostorg/lambda

switch statement case label has only `int` template argument

未关闭
#19 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C++
星标
20
派生
42
PR 合并指标
30 天内没有已合并 PR

描述

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

#include
#include

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(2147483648) is OK
}
```

This issue prone working can be eliminated in any following way:
- replace case_statement template argument from `int` to `uintmax_t` or `intmax_t` or any bigger than int. This solves that not only `int` parameters 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_type` to casts lambda parameter to that.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。