boostorg / boostorg/lambda

switch statement case label has only `int` template argument

Đang mở
#19 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C++
Star
20
Fork
42
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.